Nginx設定整體認識
預設情況下,Nginx伺服器設定檔都存放在安裝目錄Conf中,主設定檔名為nginx.conf 。其內容如下:
<code><span>#user nobody; #全局块</span> worker_processes <span>1</span>; <span>#error_log logs/<span>error</span>.log;</span><span>#error_log logs/<span>error</span>.log notice;</span><span>#error_log logs/<span>error</span>.log info;</span><span>#pid logs/nginx.pid;</span>events { <span>#events 块</span> worker_connections <span>1024</span>; } http { <span>#http块</span> include mime.types; <span>#http全局块</span> default_type application/octet-stream; <span>#log_format main '$remote_addr - $remote_user [$time_local] "$request" '</span><span># '$status $body_bytes_sent "$http_referer" '</span><span># '"$http_user_agent" "$http_x_forwarded_for"';</span><span>#access_log logs/access.log main;</span> sendfile on; <span>#tcp_nopush on;</span><span>#keepalive_timeout 0;</span> keepalive_timeout <span>65</span>; <span>#gzip on;</span> server { <span>#server块</span> listen <span>80</span>; <span>#server全局块</span> server_name localhost; <span>#charset koi8-r;</span><span>#access_log logs/host.access.log main;</span> location / { <span>#location块</span> root html; index index.html index.htm; } <span>#error_page 404 /404.html;</span><span># redirect server <span>error</span> pages to the static page /50x.html</span><span>#</span> error_page <span>500</span><span>502</span><span>503</span><span>504</span> /<span>50</span>x.html; location = /<span>50</span>x.html { <span>#location块</span> root html; } <span># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><span>#</span><span>#location ~ \.php$ { #location块</span><span># proxy_pass http://127.0.0.1;</span><span>#}</span><span># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><span>#</span><span>#location ~ \.php$ { #location块</span><span># root html;</span><span># fastcgi_pass 127.0.0.1:9000;</span><span># fastcgi_index index.php;</span><span># fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;</span><span># include fastcgi_params;</span><span>#}</span><span># deny access to .htaccess files, <span>if</span> Apache's document root</span><span># concurs with nginx's one</span><span>#</span><span>#location ~ /\.ht {</span><span># deny all;</span><span>#}</span> } <span># another virtual host using mix of IP-, name-, and port-based configuration</span><span>#</span><span>#server { #server块</span><span># listen 8000;</span><span># listen somename:8080;</span><span># server_name somename alias another.alias;</span><span># location / { #location块</span><span># root html;</span><span># index index.html index.htm;</span><span># }</span><span>#}</span><span># HTTPS server</span><span>#</span><span>#server {</span><span># listen 443 ssl;</span><span># server_name localhost;</span><span># ssl_certificate cert.pem;</span><span># ssl_certificate_key cert.key;</span><span># ssl_session_cache shared:SSL:1m;</span><span># ssl_session_timeout 5m;</span><span># ssl_ciphers HIGH:!aNULL:!MD5;</span><span># ssl_prefer_server_ciphers on;</span><span># location / {</span><span># root html;</span><span># index index.html index.htm;</span><span># }</span><span>#}</span>}</code>
從設定檔我們可以總結如下
nginix.conf配置一共有三塊組成:全域區塊、events區塊和http區塊。在http區塊中,包含多個server區塊,每個server區塊中又可以包含多個location區塊。
設定檔各模組意義
全域區塊
全域區塊是預設設定檔從開始到events模組之間的一部分內容。主要設定一下影響Nginx伺服器整體運作的設定指令,該指令作用域是Nginix伺服器全域。
通常包括運行Nginx伺服器使用者(群組)、允許生產的worker process數、Nginix進程Pid存放路徑、日誌存放路徑和類型以及設定檔引入等。
events區塊
events區塊涉及的指令主要影響Nginx伺服器與使用者的網路連線。常用配置有:
是否開啟對多worker process下的網路連線進行序列化;
是否允許同時接受多個網路連線;
選擇哪一種事件模型處理連線請求;
每個worker process 可以同時支援的最大連線數等。
這一部分指令對Nginix伺服器的效能影響較大,在實際配置中,應該根據實際情況,靈活調整。
http區塊
http區塊是Nginix伺服器設定中重要部分。代理、快取和日誌定義絕大部分功能和第三方模組的配置都可以放到這個模組。 http全域區塊中主要配置如下:
文件引入;
MIME-TYPE定義;
日誌自訂;
是否使用sendfile傳輸檔案;
連線逾時時間;
單連線請求數上線等
server區塊
server區塊和「虛擬主機」概念有著密切聯繫。每個server區塊可以相當是一台虛擬主機。 server區塊的作用域為本server區塊,不會影響到其他的server區塊。和http區塊相同,server區塊也可以包含自己的全域區塊,同時還可以包含多個location區塊。 server全域區塊主要的兩個設定如下:
虛擬主機的監聽配置;
虛擬主機的名稱或ip配置
location塊
每個server塊可以包含多個location塊,從嚴格意思來說,location其實是server就是server塊的一個指令。主要作用是,基底與Nginx伺服器接受到的請求字串,對除虛擬主機名稱之外的字串進行匹配,對特定的請求進行處理。地址定向、資料快取和應答控制等功能都在這部分實現。
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });以上就介紹了Nginx伺服器基礎配置詳解,包含了nginx,伺服器方面的內容,希望對PHP教學有興趣的朋友有幫助。