By mpojt2701
Hello, i am trying to set up a reverse proxy ssl for my wordpress domain. I have been able to set up the reverse proxy ip ssl for the wordpress, but it only apply for the main homepage. When i try to access the post or category or any other link inside the WordPress, it return with an error : 404 Not Found
I have been trying to find a solution or a guide regarding this, but so far i can not find how to solve this.
This is an example of how my set up for the reverse proxy
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
#listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
listen 443 ssl ;
listen [::]:443 ssl default_server;
#ssl on;
ssl_certificate /etc/nginx/certificate.crt;
ssl_certificate_key /etc/nginx/private.key;
root /var/www/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
proxy_pass https://example.com;
proxy_ssl_server_name on;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
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!
Hi there,
The issue you’re facing with your WordPress site when using Nginx as a reverse proxy likely stems from an improper configuration of the location / block in your Nginx configuration. Specifically, the try_files directive seems to be misconfigured for handling WordPress’s pretty permalinks.
In a typical WordPress setup, the index.php file should handle all requests that do not correspond to actual files or directories on the server. This is especially important for WordPress permalinks, which use a more SEO-friendly URL structure.
Here’s how you can modify your Nginx configuration to properly handle WordPress permalinks:
Remove the try_files $uri $uri/ =404; Line: This line is currently telling Nginx to try to serve the request as a file, then as a directory, and if neither is found, return a 404 error. This is problematic for WordPress permalinks.
Update the location / Block: Replace the try_files line with a directive that forwards all requests to WordPress’s index.php file, unless the request is for a real file or directory.
Here’s an updated version of your location / block:
location / {
proxy_pass https://example.com;
proxy_ssl_server_name on;
# Correctly handle requests for WordPress permalinks
try_files $uri $uri/ /index.php?$args;
}
In this configuration:
try_files $uri $uri/ /index.php?$args; tells Nginx to first check if the requested URI corresponds to a real file ($uri) or directory ($uri/). If neither is found, it then rewrites the request to index.php, passing the query arguments ($args). This setup is necessary for WordPress to correctly interpret and route permalinks.Ensure SSL Configuration and Certificates: Make sure your SSL certificates and keys are correctly specified and the paths are correct.
Reload Nginx Configuration: After making these changes, reload the Nginx configuration to apply them:
sudo nginx -t
sudo systemctl reload nginx
Also ensure that WordPress is configured to use permalinks. You can check this in the WordPress admin area under Settings > Permalinks.
This configuration should resolve the 404 errors you’re encountering with WordPress posts and category pages when accessing them through your Nginx reverse proxy.
Best,
Bobby
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.