• 简单配置 nginx 反向代理


    # Nginx 域名反向代理配置
    # 安装nginx
    yum install nginx -y
    # 修改配置文件
    进入配置文件目录 cd /etc/nginx/conf.d
    新建配置文件以.conf结尾 vim test.conf
    输入一下内容:
    server {
    listen 80;
    server_name a.domain.com;
    access_log /var/node/log/host.access.log main;
    location / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-Ip $remote_addr;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://192.168.2.2:7789;
    # 支持websocket
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    ##
    proxy_redirect off;
    }
    }
    server_name a.domain.com # 配置二级域名
    proxy_pass http://42.159.191.244:7789 # 配置指向web服务
    重启 service nginx restart
    访问 http://a.domain.com 即可访问到 http://192.168.2.2:7789 服务
    如果配置多个代理 即 新建配置文件 test1.conf、test2.conf(必须在/etc/nginx/conf.d 目录下建立)
    server {
    listen 80;
    server_name b.domain.com;
    access_log /var/node/log/host.access.log main;
    location / {
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-Ip $remote_addr;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://192.168.88.2:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_redirect off;
    }
    }
    输入配置内容 更改 server_name 与 proxy_pass 即可。

  • 相关阅读:
    新服务器上迁移项目遇到的问题
    xftp传输文件失败
    记录一些mysql常用命令
    微信APP支付
    状态码(更新中···)
    yii ActiveRecord
    MySQL命令行自动补全——mycli安装
    MySQL优化总结
    MySQL读写分离架构——Atlas
    MySQL日志
  • 原文地址:https://www.cnblogs.com/danny-chen/p/6202583.html
Copyright © 2020-2023  润新知