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.youkuaiyun.com/jingmo55/article/details/70801084/

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

Nginx 反向代理是一种常用的服务器配置方法,它可以将客户端的请求转到后端的多个服务器上,并将响应返回给客户端。通过反向代理,可以实现负载均衡、缓存、安全性等功能。 要配置 Nginx 反向代理,你需要编辑 Nginx 的配置文件(通常是 `nginx.conf`),然后添加相应的配置项。 以下是一个简单的 Nginx 反向代理配置示例: ``` http { upstream backend { server backend1.example.com; server backend2.example.com; server backend3.example.com; } server { listen 80; server_name example.com; location / { proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } } ``` 在这个示例中,`upstream` 块定义了后端服务器的列表。`server` 块定义了监听的端口和域名,并在 `location` 块中配置了反向代理。 `proxy_pass` 指令将请求转发到 `http://backend`,其中 `backend` 是 `upstream` 块中定义的后端服务器列表。 `proxy_set_header` 指令用于设置转发请求时的请求头。在示例中,我们设置了 `Host` 和 `X-Real-IP` 请求头。 完成配置后,保存文件并重新加载 Nginx 配置。这样,Nginx 就会将客户端的请求转发到后端服务器,并将响应返回给客户端。 请注意,以上只是一个简单的示例,实际的配置可能因具体需求而有所不同。你可以根据实际情况进行配置,并参考 Nginx 官方文档获取更多信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值