nginx 同一个ip 根据不同域名 转发到不同的内网ip

#####################changed 2010-08-11#########
#user                                   admin  admin;

#worker_processes                        8;
#worker_cpu_affinity                     00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

worker_processes                        4;
worker_cpu_affinity                     00000001 00000010 00000100 00001000;

#error_log                              /export/servers/nginx/logs/nginx_error.log  warn;
#pid                                    /export/servers/nginx/logs/nginx.pid;

worker_rlimit_nofile                    65535;

events {
                                        use epoll;
                                        worker_connections 65535;
}

http {
        include                         mime.types;
        default_type                    application/octet-stream;
        server_tokens                   off;
        log_format main                 '$remote_addr - $remote_user [$time_local] '
                                                        '"$request" $status $bytes_sent '
                                                        '"$http_referer" "$http_user_agent" ';
        charset                         utf-8;
        server_names_hash_bucket_size   128;
        client_header_buffer_size       32k;
        large_client_header_buffers     4 32k;
        client_max_body_size            300m;
        sendfile                        on;
        tcp_nopush                      on;
        keepalive_timeout               0;
        tcp_nodelay                     on;
        client_body_buffer_size         512k;

        proxy_connect_timeout           90;
        proxy_read_timeout              180;
        proxy_send_timeout              180;
        proxy_buffer_size               256k;
        proxy_buffers                   4 256k;
        proxy_busy_buffers_size         256k;
        proxy_temp_file_write_size      256k;
        proxy_hide_header               X-Powered-By;
        server_name_in_redirect         off;

        map_hash_bucket_size            1024;
        map_hash_max_size               102400;

        gzip                            on;
        gzip_min_length                 1k;
        gzip_buffers                    4 16k;
        gzip_http_version               1.0;
        gzip_comp_level                 2;
        gzip_types                      text/plain application/x-javascript text/css application/xml text/javascript image/jpeg image/gif image/png;
        gzip_vary                       on;
        gzip_disable                    "MSIE[1-6]\.";

        ssi                             on;
        ssi_silent_errors               off;
        ssi_types                       text/shtml;

        lua_code_cache                  on;
        lua_need_request_body           on;
        rewrite_by_lua_no_postpone      on;

        lua_package_path                '../lua/?.lua;../lua/?/init.lua;../lualib/?.lua;../lualib/?/init.lua;;';
        lua_package_cpath               '../lualib/?.so;;';

        lua_shared_dict cacheDomains    1m;
        add_header Access-Control-Server openresty;
        add_header X-Frame-Options SAMEORIGIN;

        include domains/*.conf;

nginx.conf 配置

在同级目录下 新建domains文件夹

比如botucarecn.conf 配置如下 其他配置大致相同 想多个域名 配置类似下 只是指向的服务器地址不同,nginx会根据匹配的域名来进行ip的转发

upstream botucare {
        server 10.1.2.249  weight=10 max_fails=2 fail_timeout=30s;
}

server {
     listen 80;
     server_name www.xxx.com;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     location  / {
                  proxy_pass http://botucare;
                }
  }

 

 

 

其他实用配置:

server {
        listen       80;
        server_name  xxx.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /hanhao/nginx/web/okexhb;
            index  index.html index.htm;
        }
include domains/*.conf;
upstream mgr {
          session_sticky;
                server 10.1.24.111:9090;
                server 10.1.24.111:8080;
    }
server {
     listen 8989;
     server_name 10.1.24.111;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     location  / {
                  proxy_pass http://mgr;
                }
     location /status {
                 deny all;
                }

     location /dyn {
                 deny all;
                }

    }

 

posted on 2018-12-18 16:28  爱屋及乌88  阅读(1369)  评论(0编辑  收藏  举报

导航