Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
NGINX wordpress 404 for all subpages

I have two problems but I think they're related. Subdirectories like /wp-admin, /blog return 404, consequently, permalinks do not work as they follow /blog/category1/page.php

My setup:

I have a server 192.168.1.4 running nginx. On another server, 192.168.1.1 I have an apache web server using virtualhosts which is hosting my wordpress site. The setup works fine without nginx, but when I turn nginx on I have a few issues.

Nginx will not work with permalinks. I have used default, so now its like: http://www.mywebsite.co.uk/?page_id=90 which works fine (as long as its not in subdirectory).

Everything in subdirectory (not in root) breaks. Including admin pages http://www.mywebsite.co.uk/wp-admin, or (before turning off permalinks) http://www.mywebsite.co.uk/blog. They all go to 404, specifically: 404 Not Found nginx/1.4.6 (Ubuntu)

Here is my config:

server {
   server_name mywebsite.co.uk www.mywebsite.co.uk;
   location / {
        index index.php;
        proxy_pass http://192.168.1.1$request_uri;

        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        try_files $uri $uri/ =404;
        #try_files $uri $uri/ /index.php?$args; #not working, error: rewrute or internal redirection cycle while interally redirecting to index.php
   }
}

For reference, here is my permalinks: /blog/%category%/%postname%/

Update

Tried adding this to my config:

server {
    ... config above ...
   location /wp-admin/ {
       index index.php
       try_files $uri $uri/ /wp-admin/index.php?$args;
       proxy_pass http://192.168.1.1$request_uri; 
       proxy_set_header Host $host; 
    }
}

this retrns an error in log:

rewrite or internal redirection cycle while internally redirecting to "/wp-admin/index.php", client: xxxxx, server: mydomain.co.uk`
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You have bits of a working configuration. The purpose of nginx in your configuration, is to reverse proxy to the Apache server. The index and try_files are inappropriate in this case. Try:

server {
    server_name mywebsite.co.uk www.mywebsite.co.uk;
    location / {
        proxy_pass http://192.168.1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
   }
}
over 4 years ago · Santiago Trujillo Report

0

Why you dont want to try wordpress without apache ? working config would be like this :

server {
    listen 80;    
    server_name site.com;
    root /home/www/site.com;

    access_log /var/log/nginx/log;
    error_log /var/log/nginx/error.log;

    index index.php;

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

    # SECURITY : Deny all attempts to access PHP Files in the uploads directory
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    }

    location = /favicon.ico { log_not_found off; access_log off; }

    location = /robots.txt {allow all; log_not_found off; access_log off; }

    error_page 404 /404.html;

    location ~ /\. { deny all; }

    location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; 
        log_not_found off; 
        expires 30d;
    }
}
over 4 years ago · Santiago Trujillo Report

0

I found in my case the problem was that mod_rewrite was not enabled. I had to run a2enmod rewrite on the server with apache

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!