【问题标题】:All Pages are Showing 404 Not Found Nginx But Homepage Working Fine所有页面都显示 404 Not Found Nginx 但主页工作正常
【发布时间】:2019-09-20 13:06:20
【问题描述】:

我正在运行一个 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 错误。甚至管理面板的工作文件。 请帮帮我...

【问题讨论】:

  • 尝试将try_files $uri $uri/ =404; 改为try_files $uri $uri/ /index.php$is_args$args;。顺便说一句,如果您是新手,有理由将 `worker_connections 100000;` 设置为 100000,开始时 1000 就足够了。
  • 不工作,仍然面临同样的错误
  • 你重启nginx了吗?你在运行wordpress吗?还是您网站的其他内容?
  • 是的,我重启了 nginx,仍然显示“404 Not Found nginx/1.15.9 (Ubuntu) error”。不,我没有使用 WordPress,我使用的是 Digitalocean 托管,只需创建 droplet,然后首先安装 nginx,然后安装 PHP-FPM 7.2,然后创建数据库,然后再安装 PhpMyAdmin。之后,我在我的目录中使用 filezilla 安装了一个 PHP 网站 - > /var/www/html 即使我已经在我的本地 XAMP 上尝试和测试了相同的脚本,它运行良好并且工作正常。
  • 请检查编辑

标签: php nginx nginx-config


【解决方案1】:

这里是 nedwos 解决问题的方法

将受影响站点的位置块中的行更改为:

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

然后重新加载 nginx

sudo systemctl reload nginx

一切都应该很好:)

Link to original question

【讨论】:

    【解决方案2】:

    尝试在默认 nginx 文件的位置路径中删除 try_files $uri $uri/ =404;。检查它是否工作

    如果没有

    删除位置路径中的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;
    
    

    粘贴到位置路径

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-14
      • 2021-03-07
      • 2018-12-03
      • 2021-06-05
      • 2019-11-12
      • 2021-07-25
      • 1970-01-01
      • 2015-05-31
      相关资源
      最近更新 更多