您现在的位置是:首页 > 文章详情  网站首页文章详情

nginx反向代理配置-其实很简单

  • Administrator
  • 3712
  • 2020-04-24 10:11:24
  • 服务器
简介配置代理代理配置很简单,只需要在location内部增加你需要的代理的网址以及端口行了。 proxy_pass http://ip:端口; 这里以localhost默认监听80端口为例,我们使用nginx代理到blog.test:8080这里。配置如下: server { l...

配置代理

代理配置很简单,只需要在location内部增加你需要的代理的网址以及端口行了。

proxy_pass  http://ip:端口;

这里以localhost默认监听80端口为例,我们使用nginx代理到blog.test:8080这里。
配置如下:

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass  http://blog.test:8080;
            root   html;
            index  index.html index.htm;
        }
            error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

配置好之后,我们打开网站就是这样的情况了
blog.test

多个代理配置

多个nginx代理,需要配置多个server,复制上面server,粘贴在下面。不要在一个server改动。
如下,我们想让当前系统的所有的8088端口转发到192.168.2.1:8088端口。
所有的8099端口转发到172.122.1.58:3306端口。
可以这写:

  • 所有8088端口转发到192.168.2.1:8088端口,添加如下代理

      # 监听所有的端口为8088
      server {
          listen       *:8088;
          server_name  blog.test;
    
          location / {
              proxy_pass  http://192.168.2.1:8088;
              root   html;
              index  index.html index.htm;
          }
      }
    
  • 8099端口转发到172.122.1.58:3306端口,添加如下代理

      # 监听所有的端口为8099
      server {
          listen       *:8099;
          server_name  blog.test;
    
          location / {
              proxy_pass  http://172.122.1.58:3306;
              root   html;
              index  index.html index.htm;
          }
      }
    

文章评论

Top