112 lines
3.3 KiB
Plaintext
112 lines
3.3 KiB
Plaintext
|
|
#① part start
|
|||
|
|
#运行nginx进程的账户
|
|||
|
|
#user www;
|
|||
|
|
#
|
|||
|
|
worker_process 1;
|
|||
|
|
error_log logs/error.log;
|
|||
|
|
pid logs/nginx.pid;
|
|||
|
|
|
|||
|
|
events{
|
|||
|
|
#use epoll;
|
|||
|
|
worker_connections 1024;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
http{
|
|||
|
|
include mime.types;
|
|||
|
|
default_type application/octet-stream;
|
|||
|
|
access_log logs/access.log main;
|
|||
|
|
#
|
|||
|
|
sendfile on;
|
|||
|
|
#
|
|||
|
|
keepalive_timeout 65;
|
|||
|
|
gzip on;
|
|||
|
|
|
|||
|
|
index index.html index.htm;
|
|||
|
|
#include /etc/nginx/conf.d/*.conf;
|
|||
|
|
#include /etc/nginx/sites-enabled/*;
|
|||
|
|
#② part start
|
|||
|
|
# 定义上游服务器列表组
|
|||
|
|
upstream web1 {
|
|||
|
|
server 127.0.0.1:1128 weight=1;
|
|||
|
|
#server 127.0.0.1:80 weight=1;
|
|||
|
|
}
|
|||
|
|
#upstream web2 {
|
|||
|
|
# server 127.0.0.2:111 weight=1;
|
|||
|
|
# server 127.0.0.2:222 weight=6;
|
|||
|
|
# server 127.0.0.2:333 weight=7;
|
|||
|
|
#}
|
|||
|
|
#定义一个服务器,其监听80端口,配置的域名是www.company.com
|
|||
|
|
server{
|
|||
|
|
listen 80;
|
|||
|
|
# using www domain to access the main website
|
|||
|
|
server_name localhost;
|
|||
|
|
#access_log logs/www.log
|
|||
|
|
|
|||
|
|
location / {
|
|||
|
|
root html;
|
|||
|
|
index index.html index.htm;
|
|||
|
|
}
|
|||
|
|
location ^~/apis/{
|
|||
|
|
proxy_pass http://127.0.0.1:1128;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#③ part start
|
|||
|
|
#定义第二个服务器,其同样监听80端口,但是匹配域名是web.company.com
|
|||
|
|
# server{
|
|||
|
|
# listen 1128;
|
|||
|
|
# # using web sub domain to access
|
|||
|
|
# server_name 192.168.77.63;
|
|||
|
|
# #access_log logs/web_access.log
|
|||
|
|
|
|||
|
|
# location / {
|
|||
|
|
# root /home/web2_root;
|
|||
|
|
# proxy_pass http://127.0.0.1:8080/web/;
|
|||
|
|
# proxy_read_timeout 300;
|
|||
|
|
# proxy_connect_timeout 300;
|
|||
|
|
# proxy_redirect off;
|
|||
|
|
|
|||
|
|
# proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
# proxy_set_header Host $http_host;
|
|||
|
|
# proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
# }
|
|||
|
|
# }
|
|||
|
|
#定义第三个服务器,其同样监听80端口,但是匹配域名是web1.company.com,并把请求转发到web1上游服务
|
|||
|
|
# server{
|
|||
|
|
# listen 80;
|
|||
|
|
# # using web1 sub domain to access
|
|||
|
|
# server_name 127.0.0.1/report;
|
|||
|
|
# # access_log logs/web1_access.log
|
|||
|
|
|
|||
|
|
# location / {
|
|||
|
|
# root html;
|
|||
|
|
# proxy_pass http://web1;
|
|||
|
|
# proxy_read_timeout 300;
|
|||
|
|
# proxy_connect_timeout 300;
|
|||
|
|
# proxy_redirect off;
|
|||
|
|
|
|||
|
|
# proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
# proxy_set_header Host $http_host;
|
|||
|
|
# proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
# }
|
|||
|
|
# }
|
|||
|
|
#定义第三个服务器,其同样监听80端口,但是匹配域名是web2.company.com,并把请求转发到web2上游服务
|
|||
|
|
# server{
|
|||
|
|
# listen 80;
|
|||
|
|
# # using web2 sub domain to access
|
|||
|
|
# server_name web2.company.com;
|
|||
|
|
# access_log logs/web2_access.log
|
|||
|
|
|
|||
|
|
# location / {
|
|||
|
|
# root /home/web2_root;
|
|||
|
|
# proxy_pass http://web2;
|
|||
|
|
# proxy_read_timeout 300;
|
|||
|
|
# proxy_connect_timeout 300;
|
|||
|
|
# proxy_redirect off;
|
|||
|
|
|
|||
|
|
# proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
# proxy_set_header Host $http_host;
|
|||
|
|
# proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
# }
|
|||
|
|
# }
|
|||
|
|
}
|