簡體   English   中英

所有頁面都顯示 404 Not Found Nginx 但主頁工作正常

[英]All Pages are Showing 404 Not Found Nginx But Homepage Working Fine

我正在運行一個 PHP 網站,其中所有子頁面都顯示 404 Not Found Nginx 但主頁和管理面板工作正常。 我正在運行在 Nginx 服務器上運行的 PHP 網站 -

這是我的默認 Nginx 文件

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name (My IP Pasted here);

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    # With php-cgi (or other tcp sockets):
    #fastcgi_pass 127.0.0.1:9000;
}

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

和 Nginx.conf 文件為


user www-data;  
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 100000;
    # 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 TLSv1.3; # 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_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

這些是我的文件,這里只是主頁工作正常,但其他子頁面在此處無法工作,出現 404 not found nginx 錯誤。 甚至管理面板工作文件。 請幫我...

是您的新設置。 請嘗試通過將重寫提供給ngnix來解決,這似乎是重寫權限問題。 還請清除您正在使用任何框架。

這是nedwos解決問題的方法

將受影響站點的位置欄中的行更改為:

try_files $uri $uri/ /index.php?q=$uri&$args;

並重新加載nginx

sudo systemctl reload nginx

一切都應該很好:)

鏈接到原始問題

嘗試刪除try_files $uri $uri/ =404; 在默認 nginx 文件的位置路徑中。 檢查它是否有效

如果不

刪除try_files $uri $uri/ =404; 在位置路徑中添加以下與您的本地主機

proxy_pass http://localhost:5000; #whatever port your app runs on
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

粘貼到位置路徑

在你的 .conf 文件上做這些修改:

查找: try_files $fastcgi_script_name /index.php& =404;

替換為: try_files $uri /index.php?$query_string;

保存修改並關閉,然后執行此 cmd : service nginx restart

阿布拉卡達布拉,你去吧

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM