nginx配置詳情(持續更新)

user  nobody [group]; //設置Nginx使用用戶,因安全會創建一新用戶,這個時候注意給新用戶授權,不然 在下面用戶創建日誌的時候回權限不夠報錯,如果測試可直接使用root


worker_processes  8;//worker進程,一般配置爲電腦核數,後面預估最大連接:worker_process*worder_connections

error_log  logs/error.log debug/notice/info/error/crit;//指定Nginx錯誤日誌的存儲目錄和日誌等級,一般生產設置爲error或crit,可以在server和http中配置具體服務的錯誤日誌, 分開管理查看,關閉錯誤日誌可使用: error_log  /dev/null crit;

pid        logs/nginx.pid;//編譯的時候指定的進程文件,默認位置在log/


events {
    worker_connections  1024;//理論單個worker最大連接數,新裝的系統一般默認是1024,即系統最大打開文件數,查看命名:ulimit -n;可以通過如下方式修改:
在/etc/security/limits.conf最後增加*soft nofile 65535   *hard nofile 65535   *soft nproc 65535  *hard nproc 65535

accept_mutex:on(default);//Nginx處理請求互斥鎖的開閉,保證連接的處理順序,在訪問量大的情況下,可以修改成off


use epoll;//事件模型,根據不同的系統選擇,linux用epoll

由於瀏覽器默認打開兩個連接到服務器,Nginx也要發兩個到服務器,真正請求連接數爲worker_process* worder_connections/4

}


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 buffer=32k //使用上述日誌格式並緩衝32k;


    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;


   upstream mytest.com{ //配置後端服務器路徑及權重
         server 127.0.0.1:8080 weight=5;
        }


    server {
        listen       80;
        server_name  localhost;

        charset koi8-r;


        access_log  logs/host.access.log  main;


        location ~* .*\.(jpg|jpeg|gif|png|swf|ico)$ {  //配置靜態文件訪問路徑,不經過後端服務器處理,實現動靜分離

         root /usr/local/tomcat/tomcat8/webapps/ROOT/;

        }


        location / { //將請求轉發到後端服務器處理
           proxy_pass http://mytest.com;
         }

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


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章