user nginx;
worker_processes 1;php
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;html
pid logs/nginx.pid;nginx
events {
worker_connections 1024;
}web
#開始##########四層端口轉發##########
stream {app
log_format 4proxy '$remote_addr $remote_port - [$time_iso8601] $status $protocol ' '"$upstream_addr" "$upstream_bytes_sent" "$upstream_connect_time"'; access_log /usr/local/nginx/logs/4proxy.log 4proxy; upstream 4lb_80 { server 192.168.4.121:80 weight=1 max_fails=3 fail_timeout=30s; } upstream 4lb_22 { server 192.168.4.121:22 weight=1 max_fails=3 fail_timeout=30s; } server { listen 10000; proxy_pass 4lb_80; proxy_timeout 300s; proxy_connect_timeout 1s; } server { listen 10022; proxy_pass 4lb_22; proxy_timeout 300s; proxy_connect_timeout 1s; }
}負載均衡
#結束##########四層端口轉發##########jsp
http {
include mime.types;
default_type application/octet-stream;tcp
log_format main '$remote_addr - $remote_user [$time_iso8601] "$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; server { listen 80; server_name localhost; charset utf-8,gbk; #access_log logs/host.access.log main; location / { root html; index index.php index.html; } 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; } # 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 /usr/local/nginx/html$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 #
#開始##########7層負載均衡##########
server {
listen 1111;
server_name web1.shou.com;
root html/web1;
index index.php index.html;
access_log logs/access_1111.log main;ide
location ~ \.php$ { root html/web1; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/web1$fastcgi_script_name; include fastcgi_params; } } server { listen 2222; server_name web2.shou.com; root html/web2; index index.php index.html; access_log logs/access_2222.log main; location ~ \.php$ { root html/web2; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/web2$fastcgi_script_name; include fastcgi_params; } } server { listen 3333; server_name web3.shou.com; root html/web3; index index.php index.html; access_log logs/access_3333.log main; location ~ \.php$ { root html/web3; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/web3$fastcgi_script_name; include fastcgi_params; } } upstream shou { server 127.0.0.1:1111 weight=1 max_fails=3 fail_timeout=30s; server 127.0.0.1:2222 weight=1 max_fails=3 fail_timeout=30s; server 127.0.0.1:3333 weight=1 max_fails=3 fail_timeout=30s backup; } server{ listen 9999; location / { proxy_pass http://shou; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffering on; proxy_buffer_size 32k; proxy_buffers 4 128k; } }
#結束##########7層負載均衡######### code
#開始##########動靜分離##########
upstream jing {
server 127.0.0.1:4444;
}
upstream dong { server 127.0.0.1:8080; } server { listen 8888; server_name web8.shou.com; access_log logs/access_8888.log main; location / { root html/web4; index index.html; } location ~* \.(jpg|png|gif)$ { proxy_pass http://jing; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffering on; proxy_buffer_size 32k; proxy_buffers 4 128k; } location ~* \.jsp$ { proxy_pass http://dong; proxy_set_header HOST $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffering on; proxy_buffer_size 32k; proxy_buffers 4 128k; }
#結束##########動靜分離##########
#開始增長索引,狀態,php
server {
listen 2222;
server_name 2222.shou.com;
access_log logs/2222_access.log main;
error_log logs/2222_error.log;
location / {
root html/shou/kodexplore;
index index.html index.php;
autoindex on;
autoindex_localtime on;
charset utf-8,gbk;
autoindex_exact_size off;
error_page 404 /404.html;
}
location = /admin { stub_status on; allow 192.168.6.0/24; allow 192.168.1.0/24; deny all; auth_basic "shou shou shou"; auth_basic_user_file auth.file; } location ~ \.php$ { root html/shou/kodexplore; index index.php index.html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
#結束增長索引,狀態,php
}