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

發佈了116 篇原創文章 · 獲贊 231 · 訪問量 70萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章