Nginx配置文件詳解

# 配置可啟動nginx的用戶
#user  user [group];
#不限制用戶則可注釋user行,或像如下配置:
#user nobody nobody;
#user  nobody;

#配置nginx工作進程數(shù),一般與cpu核數(shù)相同
#worker_processes  number | auto;
worker_processes  1;

#配置錯誤日志存放路徑及錯誤日志輸出級別(debug,info,notice,warn,error,crit,alert,emerg)
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#配置pid存放路徑
#pid        logs/nginx.pid;

#引入其他配置文件,file支持相對路徑
#include file;

events {
    #開啟nginx進程接收鏈接序列化,防止多個進程對連接的爭搶。默認為on。只能配置在events中
    #accept_mutex on | off;
    #配置是否開啟每個work process同時接收多個新到達的網絡連接,默認為off。只能配置在events中
    #multi_accept on | off;
    #配置強制使用某種事件驅動模型來處理網絡消息。method包括:select,poll,kqueue,epoll,rtsig,/dev/poll,eventport。只能配置在events中
    #use method;
    worker_connections  1024;
}


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

    #服務日志可是定義,只能在http塊中配置
    #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()傳輸文件
    sendfile        on;
    #配置每個work process每次調用sendfile()傳輸?shù)臄?shù)據(jù)量最大值;若為0則不限制
    #sendfile_max_chunk size;
    #tcp_nopush     on;

    #配置nginx與用戶建立連接會話后,nginx保持這個連接打開的一段時間(單位s)
    #keepalive_timeout  timeout[ header_timeout];
    keepalive_timeout  65;
    #該指令用于限制用戶通過某一連接向nginx服務器發(fā)送請求的次數(shù)
    #keepalive_requests number;

    #gzip  on;

    server {
        #設置監(jiān)聽IP與端口
        #監(jiān)聽所有IP的80和8000端口
        #listen *:80 | *:8000;
        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
        #
        error_page   500 502 503 504  /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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #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;
    #    }
    #}

}


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容