nginx反向代理

Window

到C:\Windows\System32\drivers\etc\目录下修改hosts文件,加入你要映射的域名如下:

127.0.0.1 dpa.xxx.com

127.0.0.1 dcas.xxx.com

配置conf下的nginx.conf文件

那我们就写个域名和端口的对应关系如下:

localhost      8088

dpa.xxx.com   8080

dcas.xxx.com   8090

具体的配置如下:

server {
       listen       80;
       server_name  dcas.xxx.com;
       location / {
         proxy_passhttp://127.0.0.1:8090/;
       }
}
server{
       listen       80;
       server_name  dpa.xxx.com;
       location / {
           proxy_passhttp://127.0.0.1:8080/;
       }
}
server{
       listen       80;
       server_name  localhost;
       location / {
          proxy_passhttp://127.0.0.1:8088/;
       }
}

Linux

添加

include /etc/nginx/conf.d/*.conf;

在/etc/nginx/conf.d目录下新建zabbix.conf文件

server {
    listen       80;                               //监听80
    server_name  zabbix.xxxx.com;   //设置访问的域名

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
      root   /var/www/zabbix;     //zabbix web的根目录
      index  index.php index.html index.htm;
    } 

    

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/zabbix;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/zabbix$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

在/etc/nginx/conf.d目录下新建jumpserver.conf文件

server {
    listen       80;   //监听80
    server_name  jumpserver.xxxx.com;  //设置访问的域名

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location /static/{
      root /usr/local/jumpserver/data/;
    }
    
    location /luna/ {
        try_files $uri / /index.html;
        alias /usr/local/luna/;  # luna 路径, 如果修改安装目录, 此处需要修改
    }

    location /media/ {
        add_header Content-Encoding gzip;
        root /usr/local/jumpserver/data/;  # 录像位置, 如果修改安装目录, 此处需要修改
    }

    location /socket.io/ {
        proxy_pass       http://localhost:5000/socket.io/;  # 如果coco安装在别的服务器, 请填写它的ip
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
    }
    
    location /coco/ {
        proxy_pass       http://localhost:5000/coco/;  # 如果coco安装在别的服务器, 请填写它的ip
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
    }
    
    location /guacamole/ {
        proxy_pass       http://localhost:8081/;  # 如果guacamole安装在别的服务器, 请填写它的ip
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
    }
    
     
   location / {
        proxy_pass http://localhost:8080/;            //访问域名指向这个ip的端口web服务(反向代理)
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    # location ~ \.php$ {
    #    root           /var/www/;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

内容源来自:https://blog.csdn.net/jingmo55/article/details/70801084/

                      https://www.cnblogs.com/sky-cheng/p/10565892.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值