ホームページ  >  記事  >  バックエンド開発  >  Nginx 設定ファイル nginx.conf の解釈

Nginx 設定ファイル nginx.conf の解釈

不言
不言オリジナル
2018-05-05 09:35:011136ブラウズ

この記事では主に 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 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。