首頁 >後端開發 >php教程 >Nginx設定檔nginx.conf解讀

Nginx設定檔nginx.conf解讀

不言
不言原創
2018-05-05 09:35:011203瀏覽

這篇文章主要介紹了關於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