Nginx Proxy HTTPS

Source: Internet
Author: User
Tags one more line openssl rsa openssl x509 server port nginx reverse proxy nginx ssl

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
  1. server {
  2. # # Server port and name # # # #
  3. Listen 443 SSL;
  4. server_name member.aoshiwei.com;
  5. SSL on;
  6. # # # SSL log Files # # #
  7. Access_log Logs/ssl-access.log;
  8. Error_log Logs/ssl-error.log;
  9. # # # SSL cert Files # # #
  10. Ssl_certificate SSL/AOSHIWEI.COM.CRT;
  11. Ssl_certificate_key Ssl/aoshiwei.com.key;
  12. # # # ADD SSL specific settings here # # #
  13. Keepalive_timeout 60;
  14. # # # limiting ciphers ########################
  15. # Uncomment as per your setup
  16. #ssl_ciphers high:! ADH;
  17. #ssl_perfer_server_ciphers on;
  18. #ssl_protocols SSLv3;
  19. ##############################################
  20. # # We want full access to SSL via backend # # #
  21. Location/{
  22. Proxy_pass http://member.aoshiwei.com;
  23. # # Force Timeouts if one of the backend is died # #
  24. Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503;
  25. # # # Set Headers # #
  26. Proxy_set_header Host $host;
  27. Proxy_set_header X-real-ip $remote _addr;
  28. Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
  29. # # Most PHP, Python, Rails, Java apps can use the This header # # #
  30. Proxy_set_header X-forwarded-proto HTTPS;
  31. # # By default we don ' t want to redirect it # # # #
  32. Proxy_redirect off;
  33. }
  34. }


Nginx Proxy HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.