🔖 添加更新示例

pull/2/head
Zhang Peng 2018-10-12 18:31:35 +08:00
parent 90cbcccbc2
commit adbcf81bc2
7 changed files with 98 additions and 45 deletions

View File

@ -1,3 +1,7 @@
#-------------------------------------------
# 简单的反向代理示例
#-------------------------------------------
upstream demo01_server {
server 127.0.0.1:9010;
}

View File

@ -1,4 +1,8 @@
#设定负载均衡的服务器列表
#-------------------------------------------
# 负载均衡示例
#-------------------------------------------
# 设定负载均衡的服务器列表
upstream demo02-server {
# weigth参数表示权值权值越高被分配到的几率越大
server 127.0.0.1:9021 weight=5;

View File

@ -0,0 +1,42 @@
#-------------------------------------------
# 多应用共用一个主域名,不同上下文的示例
#-------------------------------------------
upstream home-server {
server 127.0.0.1:9030;
}
upstream product-server {
server 127.0.0.1:9031;
}
upstream user-server {
server 127.0.0.1:9032;
}
server {
listen 80;
server_name www.demo03.com;
charset utf-8;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
# root /home/nginx/demos;
root ../../../javaapp/src/main/webapp;
location / {
proxy_pass http://home-server;
}
location /product/{
proxy_pass http://product-server;
}
location /user/ {
proxy_pass http://user-server;
}
}

View File

@ -1,15 +1,19 @@
# puck 开发环境配置
#-------------------------------------------
# 前后端分离示例
# root 为前端文件路径
# upstream backend 配置后端服务器访问地址
#-------------------------------------------
upstream backend {
server 127.0.0.1:9040;
}
# puck server
server {
listen 80;
server_name www.demo04.com;
# windows 下前后端分离场景,使用相对路径无法被识别,暂时搞不定
root D:/codes/zp/java/Nginx/demos/reactapp/dist;
root D:/Codes/ZP/Others/nginx-tutorial/demos/reactapp/dist;
location ~ ^/api/ {
proxy_pass http://backend;

View File

@ -0,0 +1,35 @@
#-------------------------------------------
# 设置文件服务器
# root 为提供文件服务的根路径
# Nginx 启动后,访问 http://localhost:9050
#-------------------------------------------
autoindex on;# 显示目录
autoindex_exact_size on;# 显示文件大小
autoindex_localtime on;# 显示文件时间
server {
charset utf-8,gbk; # windows 服务器下设置后,依然乱码,暂时无解
listen 9050 default_server;
listen [::]:9050 default_server;
server_name _;
root D:;
}
upstream demo05_server {
server 127.0.0.1:9050;
}
server {
listen 80;
server_name www.demo05.com;
charset utf-8;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
location / {
proxy_pass http://demo05_server;
}
}

View File

@ -1,38 +0,0 @@
upstream home_server {
server www.demo03.com:9030;
}
upstream product_server {
server www.demo03.com:9031;
}
upstream user_server {
server www.demo03.com:9032;
}
server {
listen 80;
server_name www.demo03.com;
charset utf-8;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
# root /home/nginx/demos;
root ../../../javaapp/src/main/webapp;
location / {
proxy_pass http://home_server;
}
location /product/{
proxy_pass http://product_server;
}
location /user/ {
proxy_pass http://user_server;
}
}

View File

@ -6,7 +6,9 @@ events {
http {
default_type application/octet-stream;
log_format main '$remote_addr - "$upstream_addr" - [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "-" "$host"';
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/nginx-http-access.log;
sendfile on;
rewrite_log on;
@ -16,7 +18,7 @@ http {
client_body_buffer_size 128k;
#common header set
proxy_http_version 1.1;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -25,5 +27,5 @@ http {
proxy_set_header Connection "upgrade";
include mime.types;
include demos/*.conf;
include conf.d/*.conf;
}