配置虚拟主机
http {
server {
listen 80; #端口号
server_name www.test.com; #域名
location / {
root data/www; # 项目路径
index index.html index.htm;
}
}
}
http {
省略...
server {
listen 443;
server_name hotel.test.com;
ssl on;
ssl_certificate /etc/nginx/cert/a.pem;
ssl_certificate_key /etc/nginx/cert/a.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;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://172.17.0.2:8008;
index index.php;
}
}
}
反向代理
- 接受请求,转发给内网的其他服务器,并返回结果给客户端
- 隐藏真实的IP地址
- 解决前后端分离跨域问题
server {
# 监听的端口
listen 80;
# 监听的域名
server_name test.domain_name.com;
# 头信息
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_pass,代理转发
location / {
proxy_pass http://api.domain_name.com;
proxy_connect_timeout 600;
proxy_read_timeout 600;
index index.php;
}
}
- 配置好反向代理, header头数据带不过去怎么办?
在http中添加 underscores_in_headers on;