I’ve spent two days trying to problem-solve this, but I’m not a developer/coder and can’t figure out what I’m doing wrong. I want to use pretty permalinks, but will get 404 errors for each page except home.
I used these DigitalOcean guides for Ubuntu 16.04 for my installation. Disabling my theme and all plugins doesn’t solve the problem, nor does using the Nginx Helper plugin.
This is what my config file at /etc/nginx/sites-available/default looks like (comments removed), but I had the same issue with the stock file and just the “try_files $uri $uri/ /index.php?$args;” changed:
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name mysite.com www.mysite.com;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
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;
}
location / {
#try_files $uri $uri/ /index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ^~ /\.well-known {
allow all;
}
location ~ /\.ht {
deny all;
}
}
My /var/log/nginx/error.log file is curiously empty.
Any help is appreciated - thanks in advance.
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!
Had to add this piece of code to both the /sites-available/default and /sites-enabled/digitalocean:
server { […] if (!-e $request_filename) { rewrite ^.*$ /index.php last; }
[…] }
It’s working for me now.
I would recommend starting here. Since WordPress was originally developed to run on Apache with mod_rewrite some custom configuration is required in order to use it with nginx. There are example configuration files there you can compare your current configuration with. Also, be sure to restart nginx when you make configuration changes so they take effect service nginx restart
Your Nginx configuration seems mostly correct for supporting pretty permalinks in WordPress. However, there are a few things you can check and modify to ensure it works correctly.
Make sure that your WordPress installation is set to use pretty permalinks:
Your Nginx configuration for handling WordPress permalinks seems fine with the try_files $uri $uri/ /index.php?$args; directive. This line is essential for pretty permalinks to work.
Ensure that your Nginx configuration file permissions are correct:
www-data or nginx) should have read access to your configuration files.After making any changes in the Nginx configuration, you must reload or restart the Nginx service:
sudo systemctl reload nginx
Ensure that PHP-FPM is running and the socket path in your Nginx config matches the actual path:
sudo systemctl status php7.0-fpm (adjust the version number as per your setup).fastcgi_pass directive in your Nginx configuration should match the PHP-FPM socket path.Ensure that the WordPress files are owned by the correct user (usually the Nginx user) and have the correct permissions:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
Adjust www-data and /var/www/html as per your setup.
wp-config.php) might contain useful information./var/log/nginx/error.log for any errors that might occur when you try to access a page./etc/nginx/sites-available/ or /etc/nginx/sites-enabled/.Since you’re using a self-signed SSL certificate, ensure that there’s no issue with the SSL configuration that might be causing the problem.
If the problem persists after checking these aspects, you might want to consult with a developer or a sysadmin. Sometimes, issues like this can be specific to your server’s setup or other configurations not covered in a standard setup.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.