Nginx implementation based on domain name HTTP, HTTPS distribution configuration sample _nginx

Source: Internet
Author: User
Tags error code one more line openssl openssl rsa openssl x509 tomcat

Tomcat Port: 8080 do the virtual host
Nginx Port: 80 assigned by domain name

Increase in HTTP in conf/nginx.conf

Copy Code code as follows:

Include www.jb51.net.conf

New conf/www.jb51.net.conf, which reads as follows:

Copy Code code as follows:

server {
Listen 80;
server_name www.jb51.net;

Location/{
Proxy_pass http://127.0.0.1:8080;
Proxy_set_header Host $host: 80;
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 127.0.0.1 is your Tomcat host IP

If the proxy https, the content is as follows:

Copy Code code as follows:

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 back-end HTTPS does not have a certificate:
Copy Code code 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 "means less SSL on;" This line

The following SERVER.CRT Server.key is a digital certificate, you can refer to OpenSSL to do the certificate

OpenSSL to do the certificate

Copy Code code as follows:

mkdir SSL
CD SSL
OpenSSL genrsa-des3-out server.key 1024 # will prompt you to enter key, as long as possible more complex, the back several to use, I copied paste
OpenSSL req-new-key server.key-out SERVER.CSR # Input Organization Information CN BeiJing Haidian huozhe.com
CP Server.key server.key.org
OpenSSL rsa-in server.key.org-out Server.key
OpenSSL x509-req-days 365-in server.csr-signkey server.key-out server.crt

SERVER.CRT Server.key Here, you can use them.

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.