I recently set up a Nginx server to host a wordpress install and am using Varnish as a reverse proxy in front of the server. Varnish is running on port 80, so I have set up Nginx to listen to 80 and redirect. Unfortunately on redirection, the port 8080 is appended to the nginx request.
Including port_in_redirect off seems to be the general solution to this problem, but it doesn’t appear to be working for me. I’ve attached the /sites-enabled/default config below. Am I doing anything wrong?! The php redirections seems to work fine, it’s only at location /where it fails.
/sites-enabled/default:
server {
listen 8080 default;
server_name "" xxx.xxx.xxx.xxx; #just using IP here (no domain yet)
port_in_redirect off;
server_name_in_redirect off;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www/site/html/;
index index index.php;
try_files $uri/ $uri /index.php?q=$uri&$args;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/site/html/$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_param SERVER_PORT 80;
}
location ~ /.ht {
deny all;
}
location ~ /.git {
deny all;
}
location ~ /.svn {
deny all;
}
}
upstream backend {
server 127.0.0.1:9000;
}
nginx.conf:
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush off;
keepalive_timeout 30;
tcp_nodelay on;
gzip on;
gzip_proxied any;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
nginx: nginx version: nginx/1.0.9
Actually, just sorted it. Simple error – in the WordPress admin site
wp-admin > Settings > WordPress address (URL)andSite address (URL)both had the port 8080 in the URL! Hence the redirection. The above setup works fine like this.If that doesn’t solve your problem a one tip I learned was to add
print_r($_SERVER["SERVER_PORT"]);in your index.php to ensure you are getting the correct port (80 in my case) set from fastcgi.Hopefully this simple step can save someone some time!