nginx : backend https, proxy_pass shows ip
        Posted  
        
            by 
                Vulpo
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by Vulpo
        
        
        
        Published on 2012-08-23T15:31:49Z
        Indexed on 
            2012/08/28
            15:41 UTC
        
        
        Read the original article
        Hit count: 374
        
I am using nginx as a reverse proxy listening at port 80 (http). I am using proxy_pass to forward requests to backend http and https servers. Everything works fine for my http server but when I try to reach the https server through nginx reverse proxy the ip of the https server is shown in the client's web browser. I want the uri of the nginx server to be shown instead of the https backend server's ip (once again, this works fine with the http server but not for the https server). See this post on the forum
Here is my configuration file :
server {
    listen 80;
    server_name domain1.com;
    access_log off;
    root /var/www;
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
location / {
    proxy_pass http://ipOfHttpServer:port/;
}
}
server {
    listen 80;
    server_name domain2.com;
    access_log off;
    root /var/www;
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
location / {
    proxy_pass http://ipOfHttpsServer:port/;
    proxy_set_header X_FORWARDED_PROTO https;
    #proxy_set_header Host $http_host;
}
}
When I try the "proxy_set_header Host $http_host" directive and "proxy_set_header Host $host" the web page can't be reached (page not found). But when I comment it, the ip of the https server is shown in the browser (which is bad).
Does anyone have an idea ?
My other configs files are :
proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_hide_header       X-Powered-By;
proxy_intercept_errors on;
proxy_buffering on;
proxy_cache_key "$scheme://$host$request_uri";
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache:10m inactive=7d max_size=700m;
user www-data;
worker_processes  2;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
 include                        /etc/nginx/mime.types;
 default_type                   application/octet-stream;
 access_log                     /var/log/nginx/access.log;
 server_names_hash_bucket_size  64;
 sendfile                       off;
 tcp_nopush                     on;
 #keepalive_timeout             0;
 keepalive_timeout              65;
 tcp_nodelay                    on;
 gzip                           on;
 gzip_comp_level                5;
 gzip_http_version              1.0;
 gzip_min_length                0;
 gzip_types                     text/plain text/html text/css image/x-icon application/x-javascript;
 gzip_vary                      on;
 include                        /etc/nginx/conf.d/*.conf;
 include                        /etc/nginx/sites-enabled/*;
}
Thanks for your help !
© Server Fault or respective owner