Report this

What is the reason for this report?

Nginx - Reverse proxy - 502 BAD GATEWAY (Only with HTTPS:// )

Posted on July 19, 2015

I am trying to make a reverse proxy server with Nginx, i have a Proxy (for HTTP) and a Proxy-SSL (For HTTPS)

I have some problems with the Proxy-SSL (HTTPS) I am getting a bad gateway 502 error when i am trying to connect to https://owncloud.example.eu

but when i use https for my example.eu site then everything is working flawless

the backend servers are LAMP’server

The logs are empty.

server {
listen 443 ssl;
server_name example.eu;


ssl on;
    ssl_certificate         /etc/nginx/ssl/wordpress/wordpress.crt;
    ssl_certificate_key     /etc/nginx/ssl/wordpress/wordpress.key;
    #ssl_trusted_certificate /etc/nginx/ssl/path/ca-certs.pem;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   # don't use SSLv3 because of killer poodles


#Uncomment to enable the settings
#gzip  on;

location / {
 # app1 reverse proxy follow
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header Host $host;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_pass https://10.0.2.5:443;
}  
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#  #  #  #  #  #  #   #  Webserver 2  #  #  #  #  #  #  #  #  #  #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

server {
listen 443 ssl;
server_name owncloud.example.eu;


 ssl on;
     ssl_certificate         /etc/nginx/ssl/owncloud  /owncloud.crt;
     ssl_certificate_key     /etc/nginx/ssl/owncloud/owncloud.key;
     #ssl_trusted_certificate /etc/nginx/ssl/path/ca-certs.pem;
     ssl_ciphers  HIGH:!aNULL:!MD5;
     ssl_prefer_server_ciphers  on;
     ssl_session_cache    shared:SSL:1m;
     ssl_session_timeout  5m;
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   # don't use SSLv3 because of killer poodles


#Uncomment to enable the settings
#gzip  on;

location / {
  # app1 reverse proxy follow
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass https://10.0.2.7:443;
} 
} 


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Did you set the SELinux? Maybe this article will help you: https://www.nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.