Nginx 部署 去掉 # 的Vue 项目(解决刷新后 访问 404)

  http {
      include       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  logs/access.log  main;

      sendfile        on;
      #tcp_nopush     on;

      #keepalive_timeout  0;
      keepalive_timeout  65;

      #gzip  on;

      server {
          listen       80;
          server_name  localhost;

          #charset koi8-r;

          #access_log  logs/host.access.log  main;

          location / {
              root   /root/project/www; #默认访问目录
              index  index.html; #默认访问文件
              try_files $uri $uri/ /index.html; #目录不存在则执行index.html
          }

          #error_page  404              /404.html;
          ... #后面的不需要修改

try_files $uri $uri/ /index.html; #目录不存在则执行index.html

你可能感兴趣的:(Nginx,Nginx,Vue)