Nginx常用配置

#進(jìn)程守護(hù)者:
user  nginx;

#錯(cuò)誤日志
error_log  logs/error.log;

#pid進(jìn)程信息:
pid        logs/nginx.pid;

#worker進(jìn)程數(shù):
worker_processes  1;

#每進(jìn)程處理連接數(shù):
worker_connections  1024;

#主配置區(qū)域結(jié)構(gòu):
http{
    #mime文件類型
    include       mime.types;

    #默認(rèn)為附件類型
    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;

    #延遲發(fā)送,優(yōu)化帶寬阻塞
    sendfile        on;
    #tcp_nopush     on;

    #等待超時(shí)時(shí)間
    #keepalive_timeout  0;
    keepalive_timeout  65;
    
    #網(wǎng)頁壓縮傳輸 
    gzip  on;
    
    #第一臺(tái)http虛擬主機(jī)配置
    server{
        #端口號(hào)
        listen       80;

        #網(wǎng)站域名
        server_name  localhost;

        #web字符集
        #charset koi8-r;

        #訪問日志
        #access_log  logs/host.access.log  main;

        #匹配192.168.2.1或192.168.2.1/
        location / {
            #設(shè)置網(wǎng)站根目錄
            root   html;

            #設(shè)置默認(rèn)首頁
            index  index.php index.html index.htm;
        }

        #設(shè)置404錯(cuò)誤頁面
        #error_page  404              /404.html;

        #設(shè)置50x錯(cuò)誤頁面
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        #訪問php文件時(shí)直接交給本機(jī)apache服務(wù)來處理
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1;
        }

        #請(qǐng)求php文件時(shí)交給php-fpm處理
        location ~ \.php$ {
            fastcgi_index  index.php;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name; 
            include        fastcgi_params;
        }

        拒絕所有人訪問.htaccess文件
        location ~ /\.ht {
            deny  all;
        }
    }

    #第二臺(tái)http虛擬主機(jī)配置
    server {
        listen       8000;
        listen       somename:8080;
        server_name  somename  alias  another.alias;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

    #配置https虛擬主機(jī)
    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;
        }
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容