0

experts.

I am trying to configure nginx/1.10.0 for upstream to 2 https web servers on non standart port with ssl termination.

Here is my current website setup in sites-available/

upstream backend {
        ip_hash;
        server 172.31.16.1:8444;
        server 172.31.16.2:8444;
}
server {
        listen 80;
        listen 443 ssl;
        listen 8444 ssl;
        ssl on;
        server_name backend_1;
        access_log /var/log/nginx/access.log;
        error_log  /var/log/nginx/error.log;
        ssl_session_cache shared:SSL:5m;

#--------ssl certificates for fronend------------#
        ssl_certificate /etc/nginx/ssl/nginxSvr.crt;
        ssl_certificate_key /etc/nginx/ssl/nginxSvr.key;
        ssl_verify_client off;

        location / {
        proxy_pass https://172.31.16.1;
#       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_ssl_certificate /etc/nginx/ssl/IPSUMCUICA.crt;
        proxy_ssl_certificate_key /etc/nginx/ssl/IPSUMCUICA.key;
        proxy_ssl_session_reuse off;
        }

It works without using upstream section. But when I change proxy_pass to proxy_pass https://backend; I got an error 404, and https://backend:8444 in browser.

Apparently it tried to resolve this name and failed, probably after some error but error log is empty in this case. All suggestions are welcome. Thank you.

6
  • 1
    If you change proxy_pass https://172.31.16.1 to proxy_pass https://172.31.16.1:8444 what happens?
    – Drifter104
    Jun 1, 2016 at 16:12
  • BTW (not connected to your problem), you should remove ssl on.
    – Alexey Ten
    Jun 1, 2016 at 17:09
  • What does the log show when you enable more detailed logging with error_log /var/log/nginx/error.log info; directive? Jun 2, 2016 at 7:06
  • If I change proxy_pass to 172.31.16.1:8444 it works(with correct /url accessed ofc). If I try to put proxy_pass backend; it goes to default 80 port. If I put backend$server_port; or backend$server_port$request_uri; and in backend section strip the port to server 172.31.16.1; - I receive 502 Bad Gateway and *2 no resolver defined to resolve backend8444 in log. Jun 2, 2016 at 9:49
  • If I try to put proxy_pass backend; - are you putting proxy_pass backend; or http://backend?
    – Drifter104
    Jun 3, 2016 at 10:49

1 Answer 1

0

Somehow I found the solution. I have added proxy_set_header Host $http_host; in location directive. Now initial config works.

upstream backend {
        ip_hash;
        server 172.31.16.1:8444;
        server 172.31.16.2:8444; } 
server {
            listen 8444 ssl;
            server_name backend_1;
            access_log /var/log/nginx/access.log;
            error_log  /var/log/nginx/error.log info;
            ssl_session_cache shared:SSL:5m;

    ssl_certificate /etc/nginx/ssl/nginxSvr.crt;
    ssl_certificate_key /etc/nginx/ssl/nginxSvr.key;
    ssl_verify_client off;

    location / {
    proxy_pass https://backend;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_ssl_session_reuse off;
    proxy_set_header Host $http_host;
        }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .