Nginx的反向代理
为了实现效果1.117.55.17:81/vod/index.html可以直接跳转到1.117.55.17:8080


运行两个tomcat
docker run -id --name:tomcat1 -p 8080:8080 镜像id
在webapps文件夹下创建/edu/index.html 并进行修改 写入你想要的html页面
docker run -id --name:tomcat2 -p 8081:8080 镜像id
在webapps文件夹下创建/edu/index.html 并进行修改 写入你想要的html页面
docker挂载并且运行
先运行容器将conf.d文件夹和nginx.conf文件都复制出来
docker run -id --name=nginx -p 80:80 镜像id
找到文件进行复制
docker cp 容器id:/etc/nginx/conf.d conf.d
docker cp 容器id:/etc/nginx/nginx.conf nginx.conf
复制出来后
进行配置文件/conf.d/defalut.conf的修改 将tomcat代理到nginx上
server {
? ? ? listen ? ? ? 80;
? ? ? server_name www.123.com;
?
? ? ? location / {
? ? ? ? ? #root ? html;
proxy_pass http://122.51.50.249:8080;
? ? ? ? ? index index.html index.htm;
? ? ? }
?
? ? ? error_page ? 500 502 503 504 /50x.html;
? ? ? location = /50x.html {
? ? ? ? ? root ? html;
? ? ? }
? ? ?
? }
运行nginx并进行挂载
docker run -di --name=nginx -p 81:80 -v ~/nginx.conf:/etc/nginx/nginx.conf -v ~/conf.d:/etc/nginx/conf.d a343d51dff65
进行验证


真实有效!!
Location的匹配规则

模式 | 含义 |
---|
location = /uri | = 用于不含正则表达式的 uri 前,要求请求字符串与 uri 严格匹配,如果匹配成功,就停止继续向下搜索并立即处理该请求 | location ^~ /uri | ^~ 开头对URL路径进行前缀匹配,并且在正则之前。 | location ~ pattern | 用于表示 uri 包含正则表达式,并且区分大小写。 | location ~* pattern | 用于表示 uri 包含正则表达式,并且不区分大小写。 | location / | 通用匹配,任何未匹配到其它location的请求都会匹配到,相当于switch中的defaut |
注意:如果 uri 包含正则表达式,则必须要有 ~ 或者 ~* 标识

|