nginx部署vue前端,刷新出现404或者500错误的解决方案

如果一直报500 检查:

静态dist文件夹是否被nginx引用到,特别是docker部署进入容器看

root   /code/dist;
server {
    listen  443 ssl;
    ssl_certificate     /etc/nginx/cert/server.crt;
    ssl_certificate_key /etc/nginx/cert/server.key;
    server_name   beta.sc.cn;
    charset                 utf-8;
    client_max_body_size    50M;

   

    location /api {
        include     uwsgi_params;
	uwsgi_param HTTP_X_FORWARDED_PROTOCOL https;
        uwsgi_pass  rookie:8000;
    }
   location / {
            root   /code/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
	}
}

 404 需要检查nginx访问文件权限问题,nginx.conf 一般第一行user  root 用户,实际访问文件用户组和用户所有权限大小访问问题:

nginx.conf 

user   root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

  

其他坑就是vue的了 路由使用mode:hash 和history nginx配置有点区别百度下

原文地址:https://www.cnblogs.com/SunshineKimi/p/15216975.html