Nginx directives + Wordpress, Default 404 issue

Discussion in 'General' started by StoneDB, Jul 21, 2017.

  1. StoneDB

    StoneDB New Member

    Hey everybody,

    First sorry for my bad english :).

    Just starting with nginx, everything works great except 404 page :mad: !

    Instead of my wordpress 404 page, nginx show default 404 page.

    [​IMG]

    My "normal" 404 page are located in my theme folder, named: 404.php

    My current nginx directives:

    Code:
    server {
            server_name www.mywebsite.com;
            return 301 $scheme://mywebsite.com$request_uri;
            listen 80;
            port_in_redirect off;
           root /var/www/clients/client0/web2/web/;
            index index.php;
           
        # Rocket-Nginx configuration
         include rocket-nginx/default.conf;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
       
        # Deny public access to wp-config.php
        location ~* wp-config.php {
            deny all;
        }
           
        location ~ \.php$ {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    
       
    }
    
    Personalized 404 page box unchecked.

    What's wrong ?

    Thanks a lot
     
    Last edited: Jul 21, 2017
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Replace your nginx directves with:

    Code:
    location / {
    try_files $uri $uri/ /index.php?$args;
    }
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
    expires max;
    log_not_found off;
    }
    
     
    dayjahone and StoneDB like this.
  3. StoneDB

    StoneDB New Member

    Hey thanks till, but your directives doesn't works too, have the same 404 page :/
     
  4. dayjahone

    dayjahone Member

    This worked, but do I have to add those directives on every wordpress site? That seems tedious.
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    This needs to be added to every site that uses WordPress. A different CMS might need no code at all or a different code. Btw, it's the same for apache web servers, just that WordPress delivers the code for apache on its own inside a .htaccess file. You can use directive snippets to manage such snippets easily in ISPConfig.
     

Share This Page