美文网首页
Nginx 转发多端口 多域名

Nginx 转发多端口 多域名

作者: Morgan7 | 来源:发表于2018-12-03 10:11 被阅读0次

    监听80端口 转发多端口

    • 以域名 www.xxx.com为例子

    监听80端口 将 test1.xxx.com 转发到8080端口
    监听80端口 将 test2.xxx.com 转发到8070端口
    监听80端口 将 www.xxx.com 转发到本地静态html路径

    user  root;
    worker_processes  2;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
    
        # 将 test1.xxx.com 转发到8080端口
        upstream test1.xxx.com {
                server 127.0.0.1:8080;
        }
        #监听80端口  将 test1.xxx.com 转发到本地8080端口
        server { 
            listen       80;
            server_name  test1.xxx.com;
            client_max_body_size 1000M;
            location / {
                proxy_pass http://test1.xxx.com;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        #监听80端口  将 test2.xxx.com 转发到8070端口
        server {
            listen       80;
            server_name  test2.xxx.com;
            client_max_body_size 1000M;
            location /{
                    proxy_pass http://ip: 8070;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        # 监听80端口 将 www.xxx.com 转发到本地静态html
        server {
            listen       80;
            server_name  www.xxx.com;
            client_max_body_size 1000M;
            location /{
                alias /usr/local/web/html/officialWebsite/;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        # 监听8888端口 这是FastDFS  转发到ngx_fastdfs_module
        server {
            listen       8888;
            server_name  ip;
            location ~/group[0-9]/ {
                    ngx_fastdfs_module;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
            root   html;
            }
        }
    }
    

    切换源码包

    cd /usr/local/src/nginx-1.15.4
    

    添加模块

    ./configure --with-http_stub_status_module --with-http_ssl_module --add-module=/usr/local/src/fastdfs-nginx-module/src/
    

    配置完成后,运行命令

    make
    

    cp

    cp ./objs/nginx /usr/local/nginx/sbin/
    

    查看安装模块

    /usr/local/nginx/sbin/nginx -V
    

    运行

    ./sbin/nginx -t
    

    相关文章

      网友评论

          本文标题:Nginx 转发多端口 多域名

          本文链接:https://www.haomeiwen.com/subject/hhiecqtx.html