环境是政务微信放请求71代理服务器,71代理服务器请求项目所在的14服务器。
1.服务器的映射
server {
listen 8080;
server_name 10.99.89.71;
#charset koi8-r;
#access_log logs/host.access.log main;
rewrite ^(.*)$ https://${server_name}$1 permanent;
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_pass https://smartgate.baoan.gov.cn/kshfwpt/H5app/index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
server {
listen 8443 ssl;
# server_name smartgate.baoan.gov.cn;
ssl_certificate /opt/sslCertificate/baoan_gov.crt;
# ssl_certificate /opt/sslCertificate/hst.crt;
ssl_certificate_key /opt/sslCertificate/baoan_gov.key;
# ssl_certificate_key /opt/sslCertificate/hst.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
#ssl_ciphers HIGH:!aNULL:!MD5;
#ssl_prefer_server_ciphers on;
location ^~/fmapi/ {
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_pass http://10.99.62.14:8080;
}
location ^~/meeting-resource-server/ {
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_pass https://10.99.62.14:8443;
当请求是https://10.99.89.71/meeting-resource-server/getRoot经过nginx映射后的地址是https://10.99.62.14:8443/meeting-resource-server/getRoot相当于只进行ip和端口的替换。
2.静态资源的替换,网上很多是本地目录映射,我这里是服务器静态资源映射。
https://10.99.89.71:8443/clientH5/mobile.html#/roomInfo是源静态资源地址。
location ^~/H5app/ {
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_pass https://10.99.62.14:8443;
}
location ^~/clientH5/ {
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_pass https://10.99.62.14:8443;
}
}
相当于匹配到clientH5后映射地址是https://10.99.62.14:8443/clientH5/mobile.html#/roomInfo;
效果:
原页面地址:
映射地址:
这是公网地址映射71代理服务器,71映射到14,能访问到,证明一条线都是通的。
3.如果要改https的端口,需要改80和443ssl一起改,监听80会将https映射到443上面,所以一起改,监听8080协议是https会映射到8443,而且访问时,不是默认端口需要加上端口,才能访问到nginx首页面。
4.证书使用时请求谁,就配谁的证书。
5.新的配置环境nginx
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8081;
server_name 192.168.89.39;
rewrite ^(.*) https://$server_name:8443$1 permanent;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 8443 ssl;
server_name 192.168.89.39;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_certificate /opt/sslCertificate/baoan_gov.crt;
ssl_certificate /opt/sslCertificate/hst.crt;
# ssl_certificate_key /opt/sslCertificate/baoan_gov.key;
ssl_certificate_key /opt/sslCertificate/hst.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
location ^~/serv/ {
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_pass https://192.168.89.35:8443;
}
location ^~/fmapi/ {
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_pass https://192.168.89.35:8443;
}
location ^~/meeting-resource-server/ {
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_pass https://192.168.89.35:8443;
}
location ^~/H5app/ {
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_pass https://192.168.89.35:8443;
}
location ^~/clientH5/ {
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_pass https://192.168.89.35:8443;
}
}
}