nginx
By rambo
nginx:
- nginx.exe -s stop //停止nginx
- nginx.exe -s reload //重新加载nginx
- nginx.exe -s quit //退出nginx
- start nginx
- nginx -s reload -c E:\nginx-1.17.1\conf\nginx.conf //重新加载配置
访问 http://hxdl.com:81/i1510_v2/team/login.jsp 自动转发
172.18.127.58:8099
nginx.conf配置
参考附件nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream site58 {
#每个请求会按照访问ip的hash值分配,这样同一客户端连续的Web请求都会被分发到同一server进行处理,
#可以解决session的问题。如果server挂掉,能自动剔除。
ip_hash;
server 172.18.127.58:8099 weight=3 fail_timeout=2s max_fails=1;
server 192.168.10.58:80 weight=1 fail_timeout=2s max_fails=1;
}
server {
listen 81;
server_name hxdl.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://site58;
index index.html index.htm;
proxy_connect_timeout 3s;
}
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
高阶配置:日志分割、灰度控制
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main escape=json '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format log_json escape=json '{"@timestamp":"$time_iso8601",'
'"@source":"$server_addr",'
'"@nginx_fields":{'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"status":"$status",'
'"host":"$host",'
'"uri":"$uri",'
'"server":"$server_name",'
'"port":"$server_port",'
'"protocol":"$server_protocol",'
'"request_uri":"$request_uri",'
'"request_body":"$request_body",'
'"request_method":"$request_method",'
'"http_referrer":"$http_referer",'
'"body_bytes_sent":"$body_bytes_sent",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"http_user_agent":"$http_user_agent",'
'"upstream_response_time":"$upstream_response_time",'
'"upstream_addr":"$upstream_addr"}}';
#access_log E:/nginx_log/access.log main;
#使用log_json格式
#access_log E:/nginx_log/access.log log_json;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream default {
#每个请求会按照访问ip的hash值分配,这样同一客户端连续的Web请求都会被分发到同一server进行处理,
#可以解决session的问题。如果server挂掉,能自动剔除。
ip_hash;
#server 172.18.127.58:8099 weight=3 fail_timeout=2s max_fails=1;
server 192.168.10.58:80 weight=1 fail_timeout=2s max_fails=1;
}
upstream site58 {
#每个请求会按照访问ip的hash值分配,这样同一客户端连续的Web请求都会被分发到同一server进行处理,
#可以解决session的问题。如果server挂掉,能自动剔除。
ip_hash;
server 172.18.127.58:8099 weight=3 fail_timeout=2s max_fails=1;
#server 192.168.10.58:80 weight=1 fail_timeout=2s max_fails=1;
}
server {
listen 80;
server_name ip160.com;
charset utf8;
#access_log E:/nginx_log/access.log log_json;
#通过cookie灰度控制
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}
access_log E:/nginx_log/api-access-$year-$month-$day.log log_json;
set $group default;
if ($http_cookie ~* "orgId=SHOW1") {
set $group site58;
}
location / {
proxy_pass http://$group;
index index.html index.htm;
proxy_connect_timeout 3s;
}
}
}
必要时可以用 两个nignx + keepalive 心跳保证 主从
记录:
时间 | 作者 | 内容 | 本版 |
---|---|---|---|
2019-07-01 | Rambo | 创建 | V1.0 |
苔花如米小,也学牡丹开。
版权声明:本文为原创文章,转载请附上链接!