version: '3.1'
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./wwwroot:/usr/share/nginx/wwwroot
events {
}
http {
server{
}
server{
}
}
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http{
include mime.type;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server{
listen 80;
server_name admin.service.itoken.oxford.com
# 所有的请求都是以 / 开始,所有的请求都可以匹配此location
location / {
root /usr/local/docker/nginx/wwwroot/htmlservice;
# 指定欢迎页面,按从左到右顺序查找
index index.html index.htm;
}
}
server{
listen 80;
server_name admin.web.itoken.oxford.com
location / {
root /usr/share/nginx/wwwroot/htmlweb;
index index.html index.htm;
}
}
}
worker_processes 1;
events {
worker_connections 1024;
}
http{
include mime.type;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 配置虚拟主机 192.168.32.255
server{
# 监听的IP和端口,配置192.168.32.255:80
listen 80;
# 虚拟主机名称,这里配置IP地址
server_name 192.168.32.255;
# 所有的请求都是以 / 开始,所有的请求都可以匹配此location
location / {
# 使用 root 指令指定虚拟主机目录即网页存放目录
# 例如:访问 http://ip/index.html 将找到 /usr/local/docker/nginx/wwwroot/html80/index.html
# 例如:访问 http://ip/item/index.html 将找到 /usr/local/docker/nginx/wwwroot/html80/item/index.html
root /usr/share/nginx/wwwroot/html80;
# 指定欢迎页面,按从左到右顺序查找
index index.html index.htm;
}
}
# 配置虚拟主机 192.168.32.255
server{
listen 8080;
server_name 192.168.32.255;
location / {
root /usr/share/nginx/wwwroot/html8080;
index index.html index.htm;
}
}
}
客户端在发送请求时,不会直接发送给目的主机.而是先发给代理服务器,代理服务器接收客户端请求后,再向主机发出,并接收目的主机返回的数据,存放在代理服务器的硬盘中,再发送给客户机
架设在客户机和目标主机之间,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到web服务器上的http请求发送到代理服务器中
反向代理服务器架设在服务器端,通过缓冲经常被请求的页面来缓解服务器的工作量,将客户机请求转发给内部网络上的目标服务器,并将从服务器上得到的结果返回给Internet上请求连接的客户端,此时代理服务器与目标主机一起对外表现为一个服务器
version: '3'
services:
tomcat1:
image: tomcat
container_name: tomcat1
ports:
- 9090:8080
tomcat2:
image: tomcat
container_name: tomcat2
ports:
- 9091:8080
user nginx;
worker_processes 1;
events {
worker_connection 1024;
}
http {
include mime.type;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 配置一个tomcat1代理服务器
upstream tomcat_server1 {
server 192.168.32.255:9090;
}
# 配置一个tomcat2代理服务器
upstream tomcat_server2{
server 192.168.32.255:9091;
}
server {
listen 80;
server_name admin.service.itoken.oxford.com
# 所有的请求都是以 / 开始,所有的请求都可以匹配此location
location / {
# 域名 admin.service.itoken.oxford.com的请求全部转发到tomcat_server1,即tomcat1服务器上
proxy_pass http://tomcat_server1;
# 欢迎页面,按照从左到右的顺序查找页面
index index.jsp index.html index.htm;
}
}
server{
listen 80;
server_name admin.web.itoken.oxford.com
location / {
# 域名 admin.web.itoken.oxford.com的请求全部转发到tomcat_server2,即tomcat2服务器上
proxy_pass http://tomcat_server2;
index index.jsp index.html index.htm;
}
}
}
user nginx;
worker_processes 1;
events {
worker_connection 1024;
}
http {
include mime.type;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream myapp {
server 192.168.32.255:9090 weight=10;
server 192.168.32.255:9091 weight=10;
}
server{
listen 80;
server_name nginx.oxford.com;
location / {
proxy_pass http://myapp;
index index.jsp index.html index.htm;
}
}
}
add_header Access-Control-Allow-Origin *或域名;
add_header Access-Control-Allow-Headers X-Requested-with;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
user nginx;
worker_processes 1;
events {
worker_connection 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name upload.myshop.com;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-with,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
location / {
proxy_pass http://192.168.32.255:8888;
if($request_method = 'OPTIONS'){
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-with;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
# 解决假请求问题,如果是简单请求则没有这个问题,这里是上传文件,首次请求为OPTIONS方式,实际请求为POST方式
add_header Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-with,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range;
return 200;
}
}
}
}