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教程有興趣的朋友有所協助。