nginx.conf 配置詳解


nginx主配置文件中的內容

pid

主線程id的存儲位置。

# cat /usr/local/nginx/logs/nginx.pid
1113
# pgrep -o nginx
1113

user

使用這個參數來配置 worker 進程的用戶和組。如果忽略 group ,那么group 的名 字等於該參數指定用戶的用戶組。

# ps -ef | grep nginx
root      1113     1  0 12月08 ?      00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www       1118  1113  0 12月08 ?      00:00:00 nginx: worker process
www       1119  1113  0 12月08 ?      00:00:00 nginx: worker process
www       1120  1113  0 12月08 ?      00:00:00 nginx: worker process
www       1121  1113  0 12月08 ?      00:00:01 nginx: worker process

error_log

錯誤日志的位置。

worker_connections

該指令配置一個工作進程能夠接受並發連接的最大數。

include

在 Nginx 的配置文件中, include 文件可以在任何地方,以便增強配置文件的可讀性,並且能夠使得部分配置文件重新使用。

include vhost/*.conf;

http

include       mime.types; #文件擴展名與文件類型映射表
default_type  application/octet-stream; #默認文件類型
sendfile on;  #開啟高效文件傳輸模式,sendfile指令指定nginx是否調用sendfile函數來 輸出文件,對於普通應用設為 on,如果用來進行下載等應用磁盤IO重負載應用,可設置 為off,以平衡磁盤與網絡I/O處理速度,降低系統的負載。注意:如果圖片顯示不正常 把這個改成off。
autoindex on; #開啟目錄列表訪問,合適下載服務器,默認關閉。
tcp_nopush on; #防止網絡阻塞
tcp_nodelay on; #防止網絡阻塞
keepalive_timeout 120; #長連接超時時間,單位是秒
gzip on; #開啟gzip壓縮輸出

server

虛擬主機
實現一台計算機對外提供多個web服務。

其中nginx.conf中的server是默認的server。

server
    {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        server_name localhost;
        index index.html index.htm index.php;
        root  /home/wwwroot/default/;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        
        include enable-php.conf;
        
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM