Question

404 Not Found nginx/1.10.0 (Ubuntu)

Hi guys,

I install wordpress on Lemp on 16.04 ( this was installed using the via DO droplet) following this tutorial https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-16-04 everything went well, but when I changed the permalinks to post-name since then apart from the home page anything else returns with this error ( 404 Not Found nginx/1.10.0 (Ubuntu) ) now I did of course followed the instruction for making changes in the /etc/nginx/sites-available/default take a look at my file below


GNU nano 2.5.3 File: /etc/nginx/sites-available/default

Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

Default server configuration

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
    http {
index index.html index.htm index.php index.nginx-debian.html;

    server_name _;

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

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #       include snippets/fastcgi-php.conf;
    #
    #       # With php7.0-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php7.0-fpm:
    #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}
    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    expires max;
    log_not_found off;

}


I didn’t follow the instructions for installing ssl because this is test and I m did made another user with sudo privileges but there was nothing in the tutorial about switching to non root user at any point, so I continued using the root user for all the process. I m completely new to this so can someone please help me with this. Also I have a sub domain that has it’s own WordPress installation but would be placed in the same dictionary and I m also planing on installing Vanilla forum as a subdomain or example.com/forum. For now I m just doing this on test environment using DO droplet and the ip address as the domain. Thanks in advance for any help.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Make sure you have your WordPress site stored in /var/www/html and set correct permissions on /var/www/html and it’s content. To check, the following simple ls command will do the job:

  1. ls -ld /var/www/html

Also, for content:

  1. ls -l /var/www/html

Recommended permissions are sammy:www-data, where sammy is your non-root user. If it’s not like that, you can set them by running:

  1. sudo chown -R sammy:www-data /var/www/html

Also, make sure you have WordPress unpacked in /var/www/html and not in /var/www/html/wordpress or anything similar. You can also post result of ls -l /var/www/html, so we’re sure you did it right.

If nothing helps, best bet are to check logs. Check for latest entries in /var/log/nginx/error.log and /var/log/nginx/access.log. The first one is the most relevant and will probably tell you the reason of error. If you’re not sure how to debug it, you can post it here (make sure to redact any sensible information).

As of forum and another WP site. You can’t do it like you explained. First, you can’t have two WP sites in one directory. The best way would be to create appropriate directories in /var/www for each site. For example in /var/www/example.com store WordPress site running on main domain - example.com, and in /var/www/subdomain.example.com store site running on the subdomain. As for forum, I wouldn’t recommend using example.com/forum as it can break WordPress permalinks. Do it with subdomains, on the same way I explained above - create directory for it, e.g. /var/www/forum.example.com and store it there. All this would require you to create appropriate Nginx server blocks and the How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04 will show you how to do it.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thanks to all, adding this > try_files $uri $uri/ /index.php?$args; to sites available worked for me.

I had the same issue after I installed the nginx on my server. The error was caused by some bad statements in my conf file. I just had to add this to the conf file:

include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_index index.php;

I used this tutorial, check maybe it will help.

Please am having problem with my debian nginx php configuration. here’s my conf file

Am hosting django in my main domain and i want to host php app called portal by typing domain/portal

but am getting 404 error

server { listen 80; listen [::]:80; server_name xxxxxxx;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/tpconnect/myproject;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/home/tpconnect/myproject/myproject.sock;
}
    location ~ /portal/.*\.php$ {
        root /var/www/html/portal;
        index index.php index.html index.htm;
        set $php_root /var/www/html/portal;

        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

location /portal {
        root /var/www/html/portal;
        index index.php index.html index.htm;
        set $php_root /var/www/html/portal;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;

        try_files $uri $uri/ /portal/index.php;
}

}