前端Nginx配置 nginx.conf文件配置

將nginx.conf文件放在根目錄下

在配置nginx的時候,最主要的是server部分:


image.png

nginx配置中路由跳轉(zhuǎn)問題解決:

try_files $uri /index.html;

如果不加這一句,在路由跳轉(zhuǎn)的時候會有問題

其余配置可參考以下源碼:

worker_processes auto;
daemon off;

error_log stderr;
events {
    worker_connections 2048;
}

http {
    access_log off;
    default_type application/octet-stream;
    include mime.types;
    sendfile on;
    keepalive_timeout 20;
    client_header_timeout 20;
    client_body_timeout 20;
    reset_timedout_connection on;
    send_timeout 20;
    gzip on;
    tcp_nopush on;
    port_in_redirect off;
    server_tokens off;
    server {
        listen  8080;
        server_name  localhost;
    
        location / {
            root /usr/share/nginx/html;
            try_files $uri /index.html;
            index index.html index.htm;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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