zoukankan      html  css  js  c++  java
  • nginx*配置 其实很简单

    配置代理

    代理配置很简单,只需要在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;
          }
      }
      
  • 相关阅读:
    CentOS 6.4 利用 Awstats 7.2 分析 Nginx 日志
    CentOS 6.4 x64 postfix + dovecot + 虚拟用户认证
    配置日志logwarch 每天发送到邮箱
    CentOSx64 安装 Gearmand 和 Gearman php扩展
    Redis之基本介绍
    Synchronized锁的基本介绍
    Lock的基本介绍
    java之threadlocal的使用
    Java之事务的基本应用
    linux之cp和scp的使用
  • 原文地址:https://www.cnblogs.com/hxsen/p/12688543.html
Copyright © 2011-2022 走看看