>  기사  >  운영 및 유지보수  >  nginx 서버를 구축하고 구성하는 방법

nginx 서버를 구축하고 구성하는 방법

WBOY
WBOY앞으로
2023-05-26 16:13:061918검색

1. 컴파일 도구 및 라이브러리 파일 설치

라이브러리 설치에 따라 반드시 순서대로 설치하세요.

(1) C++ 컴파일 환경이 설치되지 않은 경우

 yum install gcc-c++

(2) SSL 기능 openssl 라이브러리

wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
tar -zxvf openssl-1.1.0f.tar.gz
cd openssl-1.1.0f
./config make && make install

가 필요합니다. (3) 다시 쓰기 모듈에는 pcre 라이브러리

wget https://ftp.pcre.org/pub/pcre/pcre-8.01.tar.gz
tar -zxvf pcre-8.01.tar.gz
cd pcre-8.01
./configure make && make install

가 필요합니다.(4) gzip 모듈에는 zlib 라이브러리

wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure make && make install

(4) nginx 설치

wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar -zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx make && make install

두 번째, 종속 라이브러리 연결을 설정합니다.

문을 입력하는 경우: ./usr/local /nginx/sbin/nginx에서 오류가 발생했습니다.

공유 라이브러리를 로드하는 동안 오류가 발생했습니다. libpcre.so.0: 공유 개체 파일을 열 수 없습니다. 해당 파일이 없습니다. 또는 디렉토리

입력 가능:

여기서 libpcre.so.1

결과: libpcre.so: /lib64/libpcre.so.1 /usr/local/lib/libpcre.so /usr/local/lib/ libpcre.so.0

ln 명령을 다시 사용하여 libpcre.so.0을 변경하면 libpcre.so 및 libpcre.so.1이 lib64 디렉터리에 연결됩니다.

ln -s /usr/local/lib/libpcre.so.0 /lib64

3. nginx 구성

생성 nginx 실행 시 사용자 www:

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

ngix.conf 구성, 입력: vi /usr /local/webserver/nginx/conf/nginx.conf의 내용은 다음과 같이 수정됩니다:

user www www;
worker_processes 2;

error_log ../error.log;
pid    /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;
events 
{
  use epoll;
  worker_connections 65535;
}


http 
{
  include    mime.types;
  default_type application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';

 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 client_max_body_size 8m;

 sendfile on;
 tcp_nopush on;
 keepalive_timeout 60;
 tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
 gzip on; 
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text/plain application/x-javascript text/css application/xml;
 gzip_vary on;
 server 
 {
    listen    80;//端口
    server_name localhost;//域名
    index test.html index.htm index.php;//解析网页名称
    root /usr/local/nginx/html; #站点目录
  location ~ .*\.(php|php5)?$
  {
   #fastcgi_pass unix:/tmp/php-cgi.sock;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   include fastcgi.conf;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
  {
   expires 30d;
 # access_log off;
  }
  location ~ .*\.(js|css)?$
  {
   expires 15d;
  # access_log off;
  }
  access_log off;
 }

}

구성이 올바른지 확인:

/usr/local/webserver/nginx/sbin/nginx -t

시작: /usr/local/webserver/nginx/sbin/nginx

청취 프로세스: ps - ef|grep nginx

액세스 서버 IP: 192.168.1.23

nginx 서버를 구축하고 구성하는 방법

문제: 구성이 올바른 경우, IP 주소에도 액세스할 수 없습니다.

Alibaba Cloud 서버, esc 서버->보안 그룹->구성 규칙->규칙 추가 및 구성을 통해 액세스할 수 있습니다.

nginx 서버를 구축하고 구성하는 방법

nginx 서버를 구축하고 구성하는 방법

위 내용은 nginx 서버를 구축하고 구성하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제