鍍金池/ 問(wèn)答/Linux  HTML/ vue-router改變地址欄路徑或者直接在子路徑刷新會(huì)404,修改nginx配

vue-router改變地址欄路徑或者直接在子路徑刷新會(huì)404,修改nginx配置也不行

因?yàn)橄訔塿ue-router中mode:hash太丑,故而換成history,并且按照官網(wǎng)指示修改了服務(wù)器nginx的配置文件為:

 location / {
            root   html;
            index  index.html index.htm;
             try_files $uri $uri/ /index.html;  
        }

這里是nginx.conf的全配置,是不是我搞錯(cuò)了什么東西,請(qǐng)大佬給指點(diǎn)一下,感激不盡。。


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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   html;
            index  index.html index.htm;
             try_files $uri $uri/ /index.html;  
        }
       
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
  #         try_files $uri $uri/ /index.html;   
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
     #         try_files $uri $uri/ /index.html;      
    #    }
    #}

}
回答
編輯回答
陪我終

自己搗鼓了一下,總算是弄好了,姑且把過(guò)程記錄下來(lái):
-------->以下內(nèi)容僅供參考<----------
修改完nginx.conf文件后,命令行檢測(cè)一下格式是否正確,如下:

/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

提示successful表示成功,這時(shí)就需要重啟下nginx,自己試了好多重啟方法,但都失敗了(我太菜了··),
最后直接強(qiáng)制關(guān)閉:

pkill -9 nginx 

然后開(kāi)啟:

/usr/local/nginx/sbin/nginx

這就成功了

2018年5月16日 22:39
編輯回答
有你在
try_files $uri $uri/ /index.html;

添加了這個(gè)配置后,如果/index.html是存在的,排除更優(yōu)先的配置,那訪(fǎng)問(wèn)永遠(yuǎn)不會(huì)出現(xiàn)404
把nginx日志貼上來(lái)吧

2017年11月21日 01:56