Nginx Reverse Proxy

Using CentOS 6 I installed Nginx with:

yum install nginx

and amended the config file for the default website i.e.

vi /etc/nginx/conf.d/default.conf

With the following content:

upstream backend_st {
server st.domain.co.uk:80;
}
server {
listen       123.123.123.123:8080;
server_name  frontend.domain.co.uk;
include /etc/nginx/default.d/*.conf;
access_log /var/log/nginx/log/lamp.eeecs.qub.ac.uk.access.log  main;
error_log  /var/log/nginx/log/lamp.eeecs.qub.ac.uk.error.log;
root   /usr/share/nginx/html;
index  index.html index.htm;
location / {
proxy_pass  http://backend_st;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header        host           "st.domain.co.uk:80";
proxy_set_header        x-real-ip       $remote_addr;
proxy_set_header        x-forwarded-for $proxy_add_x_forwarded_for;
}
}

So visiting the web address frontend.domain.co.uk:8080 as configured under the ‘server’ section will proxy the website from st.domain.co.uk:80

Advice on the web specified using $host or configuring the proxy_set_header:

proxy_set_header        Host            $host;

However, when proxying IIS I found that I needed to actually enter the hostname rather than a variable.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>