多服务绑定80端口及映射域名

说明:业务需要配置的样例模板,如需深入了解,请查看官方文档

1.Nginx配置文件nginx.conf(可拆分多台机器部署)

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

sendfile        on;
    #tcp_nopush     on;

#keepalive_timeout  0;
    keepalive_timeout  65;

#gzip  on;
    upstream apiServices{ 
        server 192.168.1.100:80;
        server 192.168.1.101:80;
        server 192.168.1.102:80;
    }

server { 
        listen       80; 
        server_name  www.test.com;
        client_max_body_size 100M;
        location / {
            try_files $uri @www;
        }
        location @www{
            internal;
            proxy_pass http://127.0.0.1:6666;
            include req_proxy.conf;
        }
    }
    server {
        listen       80;
        server_name  maven.test.com;
        client_max_body_size 20M;
        location / {
            try_files $uri @maven;
        }
        location @maven {
            internal;
            proxy_pass http://192.168.1.103:8081;
            include req_proxy.conf;
        }
    }

server {
        listen       80;
        server_name  pbs.test.com;
        client_max_body_size 20M;
        location / {
            try_files $uri @pbs;
        }
        location @pbs {
            internal;
            proxy_pass http://192.168.1.103:8888;
            include req_proxy.conf;
        }
    }

server {# www.test.com绑定网址
        listen       6666;
        server_name  localhost;
        charset utf-8;
        server_name_in_redirect off;
        port_in_redirect off;

gzip on;
        gzip_static on;
        gzip_min_length 10k;
        gzip_types text/javascript application/javascript text/css application/json;
        gzip_proxied any;
        gzip_vary on;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        
        root    D:/web/dist;#vue项目
        index  index.html index.htm;    #目录内的默认打开文件,如果没有匹配到index.html,则搜索index.htm,依次类推--root的详解版本
        location /{
            try_files $uri $uri//index.html;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
        }

location = /index.html {
            add_header Cache-Control no-cache;
        }

location ~ /static/ {
            add_header Cache-Control no-cache;
        }

location ~ /(js/*|css/*|img/*|font/*) {
            expires 30d;
            add_header Cache-Control public;
        }

location /api/{#要访问的后端服务
            proxy_pass http://apiServices;
            proxy_cookie_path '/api' '';
            #sub_filter '127.0.0.1:8181' '192.168.1.103/api/';
            #sub_filter_once off;
        }
    }

server { #pbs.test.com绑定资源
        listen       8888;
        server_name  localhost;
        charset utf-8;
        server_name_in_redirect off;
        port_in_redirect off;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /photos {
            root  D:/resources;
            rewrite ^/photos/(.*)$ \photos\$1 break;
        }        
        location /videos {
            root  D:/resources;
            rewrite ^/videos/(.*)$ \videos\$1 break;
        }

}

}

2.include引入统计配置req_proxy.conf

proxy_connect_timeout 30s; 
proxy_send_timeout 120; 
proxy_read_timeout 120; 
proxy_buffer_size 32k; 
proxy_buffers 4 32k; 
proxy_busy_buffers_size 64k; 
proxy_redirect off; 
proxy_hide_header Vary; 
proxy_set_header Accept-Encoding ''; 
proxy_set_header Host $host; 
proxy_set_header Referer $http_referer; 
proxy_set_header Cookie $http_cookie; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

本文系转载内容,原文地址

【转载】Nginx多服务绑定80端口及映射域名的更多相关文章

  1. Nginx-多服务绑定80端口及映射域名

    多服务绑定80端口及映射域名 说明:业务需要配置的样例模板,如需深入了解,请查看官方文档 1.Nginx配置文件nginx.conf(可拆分多台机器部署) worker_processes  1; e ...

  2. 没有80端口的备案域名,如何做微信公众平台的开发?本文介绍可以通过任何域名来做开发,www.baidu.com和www.163.com和www.so.com这样的域名都可以

    1.首先做过微信开发的朋友都知道,微信后台需要绑定80端口的备案域名,如果此时手上没有80端口的备案域名就不能进行开发了吗?当然不是 首先在这些地方绑定一个备案域名,国内公司的网址基本上是有备案的如w ...

  3. Mac OS X 绑定80端口,不装nginx的小技巧

    Mac OS X 因为要绑定80端口需要ROOT权限, 但是如果用root权限启动eclipse或tomcat又会造成, 启动创建的各类文件是root的,普通用户无法删除. 为此, 我们可以通过pfc ...

  4. Ubuntu下Tomcat绑定80端口(zz)

    Ubuntu下Tomcat绑定80端口 来源:本站转载 作者:佚名 时间:2011-02-22 TAG: 工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置se ...

  5. nginx在使用非80端口做反向代理【转】

    设置nginx反向代理,nginx在使用非80端口做反向代理时,浏览器访问发现返回302错误 upstream jboss{ server max_fails= fail_timeout=20s; s ...

  6. Nginx无法启动,80端口被PID=4占用

    在nginx启动后,error.log中总是显示 80 端口被占用. 通过netstat -ano发现,其被一个叫PID=4的系统服务占用. 网上大多数的方法是说通过regidit修改注册表的方式解决 ...

  7. nginx 普通用户使用80端口启动nginx

    方法一: 依次执行如下命令 cd /usr/local/nginx/sbin/ chown root nginx chmod u+s nginx 优点是,方便简单,缺点是,既然sudo权限都不给了.这 ...

  8. Apache服务器在80端口配置多域名虚拟主机的方法

    我们在配置一台服务器的时候,如果只运行一个站点,往往过于浪费资源.Nginx和Apache都可以通过配置虚拟主机实现多站点.配置虚拟主机的方式主要有两种,一种是多个不同端口对应的多个虚拟主机站点,一种 ...

  9. ubuntu下Tomcat绑定80端口

    转载自:https://www.2cto.com/os/201102/84081.html   工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置server. ...

随机推荐

  1. 文件不同 diff --brief XX YY

    文件不同 diff --brief XX YY 文件不同 --哪些位置 diff -c XX YY 9.diff命令 diff命令用于比较多个文本文件的差异,格式为"diff [参数] 文件 ...

  2. 基于多IP地址Web服务

    [Centos7.4版本] !!!测试环境我们首关闭防火墙和selinux [root@localhost ~]# systemctl stop firewalld [root@localhost ~ ...

  3. centos更新git

    安装完centos 7后默认的git版本为1.8,有些软件需要更新版本的git,但是在yum库中并没有更高的git版本,所以需要下载安装包进行手动安装,git下载地址:https://git-scm. ...

  4. Linux Access.conf安全配置

    access.conf is the configuration file used to logins to the Linux or Unix systems. This file is loca ...

  5. python3 xlrd包的用法

    一.xlrd的安装 pip install xlrd 二.xlrd使用介绍 1.导入模块 import xlrd 2.打开Excel文件,实例化为readbook readbook = xlrd.op ...

  6. System Verilog过程块和方法

  7. TheSuperego 实验五 团队作业2:毕业设计选题系统

    项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/xbsf/2018CST 这个作业要求链接 https://www.cnblogs.com/nwnu-dai ...

  8. AI基础架构Pass Infrastructure

    AI基础架构Pass Infrastructure Operation Pass OperationPass : Op-Specific OperationPass : Op-Agnostic Dep ...

  9. 自动调度GPU的卷积层

    自动调度GPU的卷积层 这是有关如何对GPU使用自动调度程序的文档. 与依靠手动模板定义搜索空间的基于模板的autotvm不同,自动调度程序不需要任何模板.用户只需要编写计算声明,而无需任何调度命令或 ...

  10. the rust book 的简单入门笔记

    rust learning day 1 (2021/05/27) 学了常量,变量,数据类型,控制流,所有权 char 的宽度是4字节,一个 unicode 的宽度 控制流条件都不要括号 rust 中的 ...