>  기사  >  백엔드 개발  >  Nginx 구성 파일 nginx.conf 해석

Nginx 구성 파일 nginx.conf 해석

不言
不言원래의
2018-05-05 09:35:011139검색

이 글은 주로 Nginx 구성 파일인 nginx.conf의 해석을 소개합니다. 이제 모든 사람과 공유합니다. 필요한 친구들은 이를 참조할 수 있습니다.

새로 구성된 nginx nginx.conf 파일을 엽니다. 아마도 다음과 같을 것입니다:

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {
    worker_connections  1024;
}


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"';

    #access_log  logs/access.log  main;

    sendfile        on;    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;    #gzip  on;

    server {
        listen       80;
        server_name  localhost;        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        location = /50x.html {
            root   html;
        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}}

많은 코드가 눈부시게 보이지만 실제로는 복잡하지 않습니다. 단순화된 버전을 살펴보겠습니다:

# 全局区worker_processes  1;  # 有1个工作的worker子进程#可以自行修改,但太大会造成相互争夺CPU,一般来说:子进程数 = CPU数 * 核数# 配置nginx的连接特性events {
    worker_connections  1024; # 1个worker子进程能同时允许的最大连接数}# http服务器主要段http {    # 设定mime类型,类型由mime.types文件定义
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; # 是否调用sendfile来输出文件

    keepalive_timeout  65; # 连接超时时间

    # 虚拟主机段
    server {
        listen       80; # 监听端口
        server_name  localhost; # 监听主机\域名\端口

    # 定义访问响应
        location / {
            root   html; # 根目录定位
            index  index.html index.htm; # 默认访问页面定位
        }    # 定义错误提示页面
        location = /50x.html {
            root   html;
        }
}

관련 권장 사항:

Nginx 구성 파일 nginx.conf 자세한 설명

위 내용은 Nginx 구성 파일 nginx.conf 해석의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.