0.stub_status
configure arguments: --prefix=/usr/local/tengine --with-http_realip_module --with-http_gzip_static_module --with-pcre --with-http_stub_status_module --with-http_ssl_module --add-module=/opt/nginx-goodies-nginx-sticky-module-ng
[root@slave1 conf.d]# cat myserver.conf
server {
listen 80;
client_max_body_size 4G;
server_name example.com 129.211.117.78 www.example.com;
keepalive_timeout 5;
access_log /var/log/nginx/access.log ;
error_log /var/log/nginx/errors.log warn;
location / {
proxy_pass http://app_server1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location /media {
alias /opt/sudjango/nginxdjango/media;
}
location /static {
alias /opt/sudjango/nginxdjango/static;
}
location /ngx_status
{
stub_status on;
# access_log off;
allow all;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}
[root@slave1 conf.d]#
1.默认配置时,http_404状态不被认为是失败的尝试。
2.location
location / {
proxy_pass http://tomcatserver1;
index index.html index.htm;
# proxy_next_upstream
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
##如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。
proxy_connect_timeout 7s;
proxy_read_timeout 7s;
proxy_send_timeout 7s;
}
3.配置nginx.conf文件 具体配置如下
upstream report{
server localhost1:18080 max_fails=10 fail_timeout=7s;
server localhost1:28080 max_fails=10 fail_timeout=7s;
server localhost2:18080 max_fails=10 fail_timeout=7s;
server localhost2:28080 max_fails=10 fail_timeout=7s;
#ip_hash;
}
4.参考
5./home/wwlocal/wwlnginx/conf/nginx.conf
worker_processes 8;
# worker_cpu_affinity 0001 0010 0100 1000;
error_log log/error.log info;
# error_log log/error.log debug;
# error_log log/error.log notice;
# error_log log/error.log info;
pid sbin/nginx.pid;
worker_rlimit_nofile 102400;
events {
worker_connections 102400;
}
http {
include mime.types;
default_type text/plain;
log_format main '$remote_addr $host [$time_local] $status $request_time $body_bytes_sent $request_uri $upstream_addr $upstream_status " $http_user_agent" $upstream_response_time $http_headhex $connection';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 60;
keepalive_requests 2048;
gzip on;
gzip_static on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_comp_level 7;
gzip_http_version 1.1;
gzip_vary on;
gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/gif image/png;
proxy_max_temp_file_size 0;
proxy_buffer_size 64k;
proxy_buffers 4 64k;
proxy_connect_timeout 1s;
client_header_buffer_size 16k;
large_client_header_buffers 4 32k;
client_max_body_size 80m;
client_body_buffer_size 60m;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 1024;
underscores_in_headers on;
#upstream wwlproxy{
# server 255.255.255.255:80 max_fails=10 fail_timeout=1s;
# server 255.255.255.255:80 max_fails=0 backup;
#}短链后端配置请到/home/wwlocal/wwlnginx/conf/webhost.conf
include webhost.conf;
server {
listen 80;
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://wwlproxy;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
stream {
log_format tcplog "$remote_addr [$time_local] $status $session_time $bytes_sent $bytes_received $upstream_addr $upstream_connect_time $connection";
access_log logs/stream.log tcplog;
#upstream wwlconn {
# server 255.255.255.255:8080;
#}长链后端配置请到/home/wwlocal/wwlnginx/conf/tcpconn.conf
include tcpconn.conf;
server {
listen 8080 so_keepalive=30m::10;
proxy_pass wwlconn;
}
}
2,/home/wwlocal/wwlnginx/conf/webhost.conf
upstream wwlproxy{
server 192.168.1.10:80 max_fails=10 fail_timeout=1s;
server 192.168.1.20:80 max_fails=10 fail_timeout=1s;
server 192.168.1.30:80 max_fails=10 fail_timeout=1s;
server 192.168.1.10:80 max_fails=0 backup;
server 192.168.1.20:80 max_fails=0 backup;
server 192.168.1.30:80 max_fails=0 backup;
keepalive 128;
}
3.调试 nginx
用到 --with-debug
,待写。
4、如何调试 location#
可以通过在不同 location 里添加 access_log 来调试。
5、如何调试 rewrite#
rewrite_log on;
开启 nginx 日志
设置 error_log 的 level 是 notice
https://www.zhihu.com/question/30255532
用一个例子来演示会更加清晰