1. 程式人生 > >Nginx中conf相關配置的簡要說明

Nginx中conf相關配置的簡要說明



#設定執行使用者
#user  nobody;
worker_processes  1;


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


#epoll是多路複用IO(I/O Multiplexing)中的一種方式,但是僅用於linux2.6以上核心,可以大大提高nginx的效能
#pid        logs/nginx.pid;




events {
    #單個後臺worker process程序的最大併發連結數
    worker_connections  1024;
}




#設定http伺服器,利用它的反向代理功能提供負載均衡支援
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 指令指定 nginx 是否呼叫 sendfile 函式(zero copy 方式)來輸出檔案,對於普通應用,   
    #必須設為 on,如果用來進行下載等應用磁碟IO重負載應用,可設定為 off,以平衡磁碟與網路I/O處理速度,降低系統的uptime.     sendfile        on;     #tcp_nopush     on;
     sendfile        on;
    #tcp_nopush     on;
   
    #keepalive_timeout  0;
    #連線超時時間
    keepalive_timeout  65;
    #開啟gzip壓縮
    #gzip  on;
    


    #設定負載均衡的伺服器列表
    upstream webtest {
        server 127.0.0.1:8080 max_fails=0;
    }

    server {
        #偵聽80埠 
        listen       80;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;

#預設請求
        location / {
            root   html;
   #定義伺服器的預設網站根目錄位置
            index  index.html index.htm;
        }

#檢視nginx的狀態
location /NginxStatus {
            stub_status on;
            access_log logs/status_80.log;
            auth_basic "NginxStatus";
        }


location ^~ /webtest {
            root   html;
            index  index.html index.htm;
            proxy_redirect    off;
   #傳遞到後端的請求IP與埠
            proxy_set_header  Host $http_host;
   #後端的Web伺服器可以通過X-Real-IP獲取使用者真實IP
            proxy_set_header  X-Real-IP  $remote_addr;   
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://webtest;
        }




        #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;
    #    }
    #}


}