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

将nginx.conf文件放在根目录下

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


image.png

nginx配置中路由跳转问题解决:

try_files $uri /index.html;

如果不加这一句,在路由跳转的时候会有问题

其余配置可参考以下源码:

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;
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容