1. 程式人生 > 其它 >Nginx配置檔案

Nginx配置檔案

技術標籤:Nginxnginx

在linux下安裝就不說了,和別的軟體都差不多:wget壓縮包–>解壓–>./configure–>make–>make install,網上教程也非常多。

主要看一下配置檔案:

#定義worker程序的執行使用者,nobody也是一個linux使用者,一般用於啟動程式,沒有密碼。如果想自定義使用者的話可以改,不過沒必要
user nobody;

#worker程序數,通常等於CPU核心數或者核心數的二倍,虛擬機器只分了一個核心就用預設的1了。
worker_processes 1;

#全域性錯誤日誌定義型別,[ debug | info | notice | warn | error | crit ],預設是error
error_log /usr/local/nginx/logs/error.log;

#程序pid檔案,裡面就一個程序號,記錄每次啟動的pid
pid logs/nginx.pid;

#配置工作模式和連線數
event {
	# 配置每個worker程序連線數上限,nginx支援的總連線數就等於worker_connections * worker_processes
	# 比如現在這麼配併發上限就只有1024.
	# 這個值的取值上限是65535
	worker_connections 1024;
}
http {
	# 配置nginx支援哪些多媒體型別,可以在conf/mime.types檢視支援哪些多媒體型別,基本上你能想到的都支援
    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; # 開啟gzip壓縮輸出,上線的話基本都要開,可以讓IO流更小一些,響應也更快
-----------------------------------------------------------------------------------------	
	# 配置虛擬主機
    server {
    	# 如果配置多個server,那麼它們的埠號和服務名不能完全相同
    	listen       80; # 配置監聽埠 
        server_name  localhost; # 配置服務名

        #charset koi8-r; # 配置字符集,預設utf-8,不用動

        #access_log  logs/host.access.log  main; # 虛擬主機的訪問日誌,上面的是不管訪問那個虛擬主機都會記錄

		# 預設匹配 / 請求,當訪問路徑中有 / ,就會被該location匹配到並進行處理
		# 比如現在nginx啟動了,虛擬機器的ip為192.168.3.28,在瀏覽器中訪問http://192.168.3.28(:80),就被這條匹配規則
		# 攔截,跳轉到html目錄下的index.html,和tomcat的歡迎頁面一個道理
        location / {
        	# root是配置伺服器的預設網站根目錄位置,預設為nginx安裝目錄下的html目錄
            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;
    #    }
    #}

}