首頁 >後端開發 >php教程 >初識nginx設定檔--nginxconf nginx配置tcp nginx設定jsp nginx直播配

初識nginx設定檔--nginxconf nginx配置tcp nginx設定jsp nginx直播配

WBOY
WBOY原創
2016-07-29 08:53:17962瀏覽

1.開啟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;
	    proxy_pass http://192.168.56.202:8080;	
        }

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

}
簡單點可以理解成如下幾個區塊:

...				#全局块

events				#event块
{
...
}
http				#http块
{
...				#http全局块	
}
server				#server块
{
...				#server全局块
	location [PATTERN]	#location块
	{
	...	
	}
	location [PATTERN]	#location块
	{
	...	
	}
}
server				#server块
{
...
}
...
}

2.各個區塊的作用

全塊:主要設定一些影響伺服器整體運作的配置,其作用域是全域的。通常包括伺服器
的使用者、允許產生的worker process(此設定項一般為伺服器主機的核數),nginx的進程pid
的存放路徑、日誌的存放路徑和類型以及設定檔的引入


events區塊:主要設定一些影響伺服器與使用者的網路連結的參數,常用的有:是否開啟對
多worker process下的網路連線進行序列化、師傅允許同時接收多個網路連線、每個
worker process可以同時支援的最大連線數。


http區塊:一般設定代理程式、快取、日誌定義等絕大多少的功能和第三方的設定都在這個模組中設定


server區塊:與虛擬主機有關


location區塊:對請求的處理、地址定向、回應控制

以上就介紹了初識nginx設定檔--nginxconf,包括了nginx,設定檔方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn