Ngnix配置虚拟主机和反向代理

2019-08-15  本文已影响0人  iDevOps
配置虚拟主机
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;
     }
    }
}

反向代理
  1. 接受请求,转发给内网的其他服务器,并返回结果给客户端
  1. 隐藏真实的IP地址
  2. 解决前后端分离跨域问题
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;
        }
 }
在http中添加 underscores_in_headers on;
上一篇 下一篇

猜你喜欢

热点阅读