I am facing a similar problem as this question where I am using Nginx as a proxy for Apache server (Ubuntu) running WordPress. The internal links of the website all give 301 redirects to localhost.

For instance, the link: wwww.example.com/internal-link redirects to localhost/internal-link which gives error 404.

The Apache configurations are as follow:

<VirtualHost *:80>
        <Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted

        ServerAdmin email@email.com
        ServerName example.com
        ServerAlias www.example.com
        ServerAlias *.example.com
        DocumentRoot /var/www/html

The Nginx configuration file is as follow:

server {
       # Where IP is server IP and example is the domain name
       listen       IP:80;
       server_name  static.example.com;

       location / {
           proxy_pass http://localhost:8480;
           proxy_set_header X-Real-IP $remote_addr;


server {
       listen       IP:80;
       server_name  example.com;
       rewrite      ^ $scheme://www.example.com$request_uri redirect;

server {
        listen       IP:80;            # your server's public IP address
        server_name  www.example.com;   # your domain name

    location / {
        proxy_pass http://localhost:8020;
        proxy_set_header X-Real-IP $remote_addr;

The .htaccess is the default generated by WordPress:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

here is some of the records for Apache's access log: - - [15/Jul/2016:07:11:31 -0400] "GET /link/ HTTP/1.0" 301 335 "-" "Mozilla/5.0 (compatible; Cliqzbot/1.0 +http://cliqz.com/company/cliqzbot)" - - [15/Jul/2016:07:08:02 -0400] "GET /link/ HTTP/1.0" 404 5396 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) 

any idea what is causing this and how to fix it?

  • Is apache issuing the redirects or nginx? Please post your nginx configuration. – EEAA Jul 15 '16 at 20:13
  • @EEAA how can I check if Apache is issuing the redirect? I don't have access to nginx configuration – Rain Man Jul 15 '16 at 20:14
  • The redirects should be logged in the apache access_log. You're likely going to need to change your nginx configuration for this to work, though. – EEAA Jul 15 '16 at 20:15
  • Why are you using both Nginx and Apache? I run Nginx and PHP for Wordpress, Apache not required. What happens if you take away either Nginx or Apache? Nginx/Wordpress tutorial: photographerstechsupport.com/tutorials/… – Tim Jul 17 '16 at 5:19
  • 1
    I was asking about the why. It would be useful to see a curl for a resource, and the corresponding entries in the Nginx and Apache logs. That will tell us where the 301 is coming from and will help narrow down how to fix it. – Tim Jul 22 '16 at 0:04

I use following NGINX server block to proxy_pass all requests to local Apache HTTP Server:

# cat /usr/local/etc/nginx/conf.d/apache24.conf 
server  {
    listen 80;

    location    /   {
        proxy_set_header    Host    $host;
        proxy_set_header    X-Forwarded-For $remote_addr;
        proxy_set_header    X-Real-IP   $remote_addr;
        proxy_pass_header   server;

and Apache's HTTP Server VirtualHost configured normal way.

  • this should be placed instead of last server configuration in the file? I never worked with nginx so not sure – Rain Man Jul 21 '16 at 15:27
  • @RainMan I dont know how your environment setup, so I cannot tell you to replace anything there, but I would recommend you to make a backup before making any changes, but the idea is if you're using default nginx.conf and use include conf.d/*.conf; you can then place this into your conf.d and it should work) – alexus Jul 21 '16 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.