鍍金池/ 問(wèn)答/Linux/ nginx直接輸入url訪問(wèn)純html頁(yè)面,報(bào)錯(cuò)404 Not Found,或者

nginx直接輸入url訪問(wèn)純html頁(yè)面,報(bào)錯(cuò)404 Not Found,或者主頁(yè)面(index)刷新報(bào)錯(cuò)

貌似apache也會(huì)這樣。

clipboard.png

nginx配置只改動(dòng)了server
clipboard.png

這是linux下的目錄

user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;

    ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        server{
                listen  80      default_server;
                rewrite ^/(.*)  http://www.leisuremoment.com/$1 permanent;
                server_name www.leisuremoment.com;
                location / {
                        root    /var/www/html;
                        index   index.html index.htm;
                        try_files       $uri    $uri/   /var/www/html/index.html;
                }
                error_page      404     /404.html;
                        location = /40x.html{ }
                error_page 500 502 503 504 /50.html;
                        location = /50x.html{  }
        }


        include /etc/nginx/sites-enabled/*;
}

clipboard.png

個(gè)人網(wǎng)站,index頁(yè)面刷新沒(méi)有問(wèn)題,但是進(jìn)入其他頁(yè)面刷新就gg了。
http://leisuremoment.com/

回答
編輯回答
拼未來(lái)

你把你的nginx配置信息貼出來(lái),然后再把你訪問(wèn)的url放出來(lái),大家就可以分析出來(lái)問(wèn)題在哪了

2018年2月1日 21:43
編輯回答
菊外人

配置里沒(méi)寫try_files吧?


更新

看了下配置,說(shuō)下發(fā)現(xiàn)的幾個(gè)問(wèn)題:

  1. rewrite ^/(.*) http://www.leisuremoment.com/$1 permanent;try_files不要一起用。后者就是解決(優(yōu)化)前者來(lái)的,一起用不亂套了?
  2. 關(guān)于try_files /var/www/html/index.html;這條,前邊已經(jīng)用root定位過(guò)根目錄了,后邊實(shí)際上出來(lái)的都是基于根目錄的指向,再多套完整路徑進(jìn)去就不對(duì)了。
  3. try_files還是先寫成try_files $uri $uri/ /index.html;
  4. 這段:

    error_page      404     /404.html;
    location = /40x.html{ }
    error_page 500 502 503 504 /50.html;
    location = /50x.html{  }

    下邊的倆location是空的,沒(méi)意義的建議直接刪掉。另外建議確認(rèn)下是不是真的有404.html50.html,沒(méi)有的話這兩句error_page也是可以刪掉的,直接讓系統(tǒng)顯示默認(rèn)的報(bào)錯(cuò)就好。

  5. 建議去看下access.log,看下URI請(qǐng)求映射到系統(tǒng)內(nèi)是哪個(gè)路徑,大概就能清楚是哪里有錯(cuò)了。
2017年12月2日 20:07
編輯回答
汐顏

首先查看web根目錄下index.html是否存在,其次查看nginx的conf.d

# 定義服務(wù)器默認(rèn)網(wǎng)站根目錄
root    /var/www/html;
location / {
    # 定義首頁(yè)索引文件的名稱
    index  index.html index.htm;
}
2017年10月19日 03:54