5

I am running a PHP Website Where all Sub Pages are showing 404 Not Found Nginx But Homepage and Admin Panel is working fine. I am running Php website which is running on Nginx Server -

Here is my Default Nginx File

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;
}}   

And Nginx.conf file as


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/*;
}

These are my files, Here is just homepage working fine but the other sub pages are not working here is getting the 404 not found nginx error. Even the Admin Panel working file. Please Help me...

Vijay Singh
  • 71
  • 1
  • 5
  • Try change the line `try_files $uri $uri/ =404;` to `try_files $uri $uri/ /index.php$is_args$args;`. BTW, if your side is new, there is reason to set ` worker_connections 100000;` to 100000, 1000 will be much more sufficient to begin with. – hcheung May 02 '19 at 09:41
  • Not working, still facing the same error – Vijay Singh May 02 '19 at 23:35
  • did you restart the nginx? are you running wordpress? or something else for your website? – hcheung May 03 '19 at 01:25
  • Yes, I have restart nginx, still it is showing "404 Not Found nginx/1.15.9 (Ubuntu) error". No, I'm not using WordPress, I am using Digitalocean hosting and simply create the droplet then install first nginx and then install PHP-FPM 7.2 and then Create Database and then PhpMyAdmin. After it I have installed a PHP Website using filezilla on my directory -> /var/www/html Even I have tried and tested the same script on XAMP in my local and it fabulous running and working fine. – Vijay Singh May 03 '19 at 02:13
  • Please Check Edit – Vijay Singh May 03 '19 at 02:31
  • Here is my Nginx Default Error Log File - -- 2019/05/02 01:57:29 [emerg] 14537#14537: unexpected end of file, expecting "}" in /etc/nginx/sites-enabled/default:92 2019/05/02 01:59:13 [notice] 14565#14565: signal process started 2019/05/02 02:02:06 [notice] 15984#15984: signal process started 2019/05/02 02:21:13 [notice] 26291#26291: signal process started 2019/05/02 02:24:54 [notice] 26307#26307: signal process started 2019/05/02 02:32:12 [notice] 26333#26333: signal process started 2019/05/03 02:11:48 [notice] 2385#2385: signal process started -- – Vijay Singh May 03 '19 at 02:35

2 Answers2

9

Here is nedwos solution to the problem

Change the line in the location block of the affected site to:

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

and reload nginx

sudo systemctl reload nginx

All should be well :)

Link to original question

Bobby Axe
  • 1,491
  • 13
  • 29
0

try removing try_files $uri $uri/ =404; in location path of default nginx file. check if it's work

if not

remove try_files $uri $uri/ =404; in location path add the following with your localhost

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;

paste in location path