9

I have a wordpress blog which is served by apache2(on port 80) and nginx(on port 8080) on Ubuntu 12.04. Now whenever a client connects via port 80 all is hunky dory, but when a client connects to 8080 to view the same blog, the connection is redirected to apache. Why is this happening? I searched around and found that this is a Wordpress limitation that it redirects all connections to the Site URL set in the dashboard(which is port 80 by default).

Is there a way around this? that the connections to port 8080 would be served by nginx rather than apache

Contents of /etc/nginx/sites-enabled/wordpress

server {
listen   8080;

root /var/www;
index index.php index.html index.htm;

server_name abc.com;

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

location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
        root /usr/share/nginx/www;
}

location ~ \.php$ {

        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param   SERVER_PORT 8080;
        port_in_redirect off;
}

Any help is appreciated.

  • 2
    WP can only be configured to run on one port. It will either be mysite.com or mysite.com:8080 not both. When someone views WP via 8080 (but configured for 80), WP would probably show the page but all links will be 80. – user42826 Feb 20 '14 at 17:01
  • Why are you trying to run the site on like this? – Seamus Leahy Feb 21 '14 at 3:18
  • @user42826 I've configured apache to use 8080, and, as you described, all links to css, images, and other assets are broken. How do you suggest fixing that wouldn't remove redirects? I've seen a lot of people recommend adding :8080 to the url in settings, but this doesn't feel right. I shouldn't have to configure WP in addition to apache, no? – user658182 Oct 3 '14 at 2:20
11

I solved it!! here's how:

Edit your current theme's functions.php and add following line after the opening PHP tag to disable canonical redirection.

remove_filter('template_redirect','redirect_canonical'); save and exit.

Restart apache2 and nginx and check with curl -I IP.

1

Same problem. In my situation, I set the server port at 3030, to accommodate other servers. Anyway, without having to add any code to any functions.php files, I solved the problem by changing the site and home values in the wp_options table to the domain and port setting.

For example,

site     http://localhost:3030
home     http://localhost:3030

Everything seemed to work fine from there. 👍

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.