系統(tǒng)環(huán)境:Windows Server 2012 R2
軟件版本:nginx(1.16.0) apache-tomcat-7.0.57
直奔主題:
Nginx主要配置
監(jiān)聽80端口
server {
listen 80;
server_name 域名1;
location / {
root html;
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8081;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name 域名2;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host remote_addr;
proxy_set_header X-Forwarded-For scheme;
proxy_pass http://localhost:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
重點:監(jiān)聽443端口
server {
listen 443;
server_name 域名1; # localhost修改為您證書綁定的域名。
ssl on; #設置為on啟用SSL功能。
root html;
index index.html index.htm;
ssl_certificate cert/xxxxxx域名1.pem; #將domain name.pem替換成您證書的文件名。
ssl_certificate_key cert/xxxxxx域名1.key; #將domain name.key替換成您證書的密鑰文件名。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用該協(xié)議進行配置。
ssl_prefer_server_ciphers on;
location / {
root html; #站點目錄。
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host remote_addr;
proxy_set_header X-Forwarded-For scheme;
proxy_pass http://localhost:8081;
}
}
server {
listen 443;
server_name 域名2; # localhost修改為您證書綁定的域名。
ssl on; #設置為on啟用SSL功能。
root html;
index index.html index.htm;
ssl_certificate cert/xxxxxx域名2.pem; #將domain name.pem替換成您證書的文件名。
ssl_certificate_key cert/xxxxxx域名2.key; #將domain name.key替換成您證書的密鑰文件名。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用該協(xié)議進行配置。
ssl_prefer_server_ciphers on;
location / {
root html; #站點目錄。
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host remote_addr;
proxy_set_header X-Forwarded-For scheme;
proxy_pass http://localhost:8080;
}
}
tomcat配置:
實例1 tomcat
1、將<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
改為
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
2、Host標簽下添加如下配置(重點):
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
remoteIpProxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"
/>
其他實例tomcat配置同上。
注意問題:
第一次我的tomcat配置為:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" proxyPort="443" />
https請求跳轉(zhuǎn)時會出現(xiàn)400 Bad Request的問題,把proxyPort="443"去掉解決。
希望這篇文章能幫助到大家!