nginx配置示例

# 進(jìn)程啟動(dòng)時(shí)worker數(shù)目,建議設(shè)置為CPU核數(shù)的1~2倍(我的是雙核線程的)
worker_processes  4;
# 每個(gè)worker最大連接數(shù)目,默認(rèn)是1024
events {
    worker_connections  10240;
}

http {
    # 包含nginx.conf同目錄下的配置文件 'mime.types'
    include       mime.types;
    # 默認(rèn)的返回類型
    default_type  application/octet-stream;
    # nginx通過(guò)使用sendfile指令來(lái)控制是不是用linux提供的零拷貝功能,默認(rèn)是on(開啟),否則是off
    sendfile        on;
    # 請(qǐng)求超時(shí)時(shí)間
    keepalive_timeout  65;

    # 默認(rèn)虛擬主機(jī)
    server {
        listen       80;
        # 虛擬主機(jī)名稱
        server_name  localhost;

        location / {
            # 虛擬主機(jī)根目錄
            root   /home/linzh/workspace/application/public;
            # 默認(rèn)訪問(wèn)的文件
            index  index.html index.php index.htm;
            # 重新規(guī)則
            if (!-e $request_filename) {
                # 訪問(wèn)這些文件夾不重寫
                rewrite ^/(assets|img|js|css|font)/.* break;
                # index.php重寫,都懂的
                rewrite ^/(.*)$ /index.php/$1 last;
            }
        }
        #錯(cuò)誤頁(yè)面,可以在nginx安裝目錄下找到這個(gè)文件 50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
        # 訪問(wèn)的文件以.php結(jié)尾的,調(diào)用php-fpm(注意需要?jiǎng)h除".php$"最后的$符號(hào))
        location ~ \.php {
            # 根目錄 
            root           /home/linzh/workspace/application/public;
            # php-fpm監(jiān)聽地址
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            # 下面兩段的作用是支持path_info設(shè)置
            fastcgi_split_path_info ^(.+\.php)(.*)$;  
            fastcgi_param PATH_INFO $fastcgi_path_info; 
            # fastcgi參數(shù)
            fastcgi_param  SCRIPT_FILENAME  /home/linzh/workspace/application/public$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    # 另一個(gè)虛擬主機(jī),配置同上,區(qū)別是server_name
    server {
        listen       80;
        server_name  demo.me;

        location / {
            root   /home/linzh/workspace/demo/public;
            index  index.html index.php;
            if (!-e $request_filename) {
                rewrite ^/(assets|img|js|css|font)/.* break;
                rewrite ^/(.*)$ /index.php/$1 last;
            }
        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }

        location ~ \.php {
            root           /home/linzh/workspace/demo/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;    
            fastcgi_param PATH_INFO $fastcgi_path_info;    
            fastcgi_param  SCRIPT_FILENAME  /home/linzh/workspace/demo/public$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

}
最后編輯于
?著作權(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),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

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