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.