美文网首页
Ngnix配置虚拟主机和反向代理

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

作者: iDevOps | 来源:发表于2019-08-15 18:41 被阅读0次
配置虚拟主机
  • http
http {
  server {
    listen       80;  #端口号
    server_name  www.test.com; #域名
    location / {
        root   data/www;  # 项目路径
        index  index.html index.htm;
    }
 }
}

  • https
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;
        }
 }
  • 配置好反向代理, header头数据带不过去怎么办?
在http中添加 underscores_in_headers on;

相关文章

网友评论

      本文标题:Ngnix配置虚拟主机和反向代理

      本文链接:https://www.haomeiwen.com/subject/uflnjctx.html