准备
windows环境
去nginx官网下载nginx
http://nginx.org/en/download.html
然后打开conf目录下的nginx.conf
反向代理http
nginx.conf配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server{
listen 80; # 监听端口
server_name test1_http.com;#域名
location / {
proxy_pass http://test2_http.com; # 需要代理的域名
proxy_set_header X-Real-IP $remote_addr; # 请求头中设置 用户真实ip
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
}
}
}
反向代理https
nginx.conf配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 443 ssl; #监听 默认端口
server_name test1_https.com;
#https证书配置
ssl_certificate SSL.crt; # 建议相对路径
ssl_certificate_key SSL.KEY;#建议相对路径
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
#针对源点使用https,需要下面一段
proxy_ssl_server_name on;
proxy_pass https://test2_https.com; # 需要代理的域名
proxy_set_header X-Real-IP $remote_addr;# 请求头中设置 用户真实ip
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
}
}
}
端口映射tcp
配置stream需要和http同级
worker_processes 1;
events {
worker_connections 1024;
}
#映射
stream {
#将4422端口转发到test1_https.com的4433端口
upstream server_upstreams_port4433 {
server test1_https.com:4433;
}
server {
listen 4422; 监听端口
proxy_pass server_upstreams_port4433; 转发
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 443 ssl; #监听 默认端口
server_name test1_https.com;
#https证书配置
ssl_certificate SSL.crt; # 建议相对路径
ssl_certificate_key SSL.KEY;#建议相对路径
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
#针对源点使用https,需要下面一段
proxy_ssl_server_name on;
proxy_pass https://test2_https.com; # 需要代理的域名
proxy_set_header X-Real-IP $remote_addr;# 请求头中设置 用户真实ip
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
}
}
}
网友评论