server {
Listen 443;
server_name mail.jb51.net;
SSL on;
Ssl_certificate SERVER.CRT;
Ssl_certificate_key Server.key;
Location/{
Proxy_pass https://192.168.0.2:443;
Proxy_set_header Host $host: 443;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header Via "Nginx";
}
}
Where 192.168.0.2 is your HTTPS host
This can be simplified if the backend https does not have a certificate:
Copy CodeThe code is as follows:
server {
Listen 80;
server_name svn.jb51.net;
Location/{
Proxy_pass https://192.168.0.2:443;
Proxy_set_header Host $host: 443;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header Via "Nginx";
Proxy_set_header X-forwarded-proto HTTPS; #注意看这里 one more line.
}
}
If you are prompted, SSL receives a record that exceeds the maximum allowable length. "Error code" Ssl_error_rx_record_too_long "description less" SSL on; " This line
Nginx Reverse Proxy HTTPS
Description
1.nginx 1.2.0 CentOS 6.2
2. This refers to the reverse proxy https refers to the Nginx SSL server, Nginx and back-end server communication or HTTP, of course, can also be implemented Nginx and back-end server to implement HTTPS communication, but this article does not test
Steps:
Nginx to implement SSL, at compile time to add--with-http_ssl_module, such as:
./configure--with-http_ssl_module
#cd/usr/local/nginx/conf
#mkdir SSL
#cd SSL
Generate a private key
# OpenSSL Genrsa-des3-out Aoshiwei.com.key 1024
Prompt to enter a password
Generate a CSR (Certificate Signing Request) file:
# OpenSSL Req-new-key aoshiwei.com.key-out AOSHIWEI.COM.CSR
Fill in the certificate content, organization, domain name, etc., Common name fill in the domain name
# CP Aoshiwei.com.key Aoshiwei.com.key.bak
# OpenSSL rsa-in aoshiwei.com.key.bak-out Aoshiwei.com.key
# OpenSSL x509-req-days 365-in aoshiwei.com.csr-signkey aoshiwei.com.key-out aoshiwei.com.crt
Add in nginx.conf:
[Plain]View Plaincopy
- server {
- # # Server port and name # # # #
- Listen 443 SSL;
- server_name member.aoshiwei.com;
- SSL on;
- # # # SSL log Files # # #
- Access_log Logs/ssl-access.log;
- Error_log Logs/ssl-error.log;
- # # # SSL cert Files # # #
- Ssl_certificate SSL/AOSHIWEI.COM.CRT;
- Ssl_certificate_key Ssl/aoshiwei.com.key;
- # # # ADD SSL specific settings here # # #
- Keepalive_timeout 60;
- # # # limiting ciphers ########################
- # Uncomment as per your setup
- #ssl_ciphers high:! ADH;
- #ssl_perfer_server_ciphers on;
- #ssl_protocols SSLv3;
- ##############################################
- # # We want full access to SSL via backend # # #
- Location/{
- Proxy_pass http://member.aoshiwei.com;
- # # Force Timeouts if one of the backend is died # #
- Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503;
- # # # Set Headers # #
- Proxy_set_header Host $host;
- Proxy_set_header X-real-ip $remote _addr;
- Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
- # # Most PHP, Python, Rails, Java apps can use the This header # # #
- Proxy_set_header X-forwarded-proto HTTPS;
- # # By default we don ' t want to redirect it # # # #
- Proxy_redirect off;
- }
- }
Nginx Proxy HTTPS