nginx: [emerg] "proxy_buffer" directive is not allowed here
微wx笑 2022-10-10【网页网站】 0 0关键字: nginx
nginx version windows 1.10.3,当设置 proxy_buffer 32 4k; 时,nginx -t 输出:nginx: [emerg] "proxy_buffer" directive is not allowed here配置文件如下:#user nobody;worker
nginx version windows 1.10.3,当设置 proxy_buffer 32 4k; 时,nginx -t 输出:nginx: [emerg] "proxy_buffer" directive is not allowed here
配置文件如下:
#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;
#设置允许发布内容为10M
client_max_body_size 10M;
client_body_buffer_size 128k;
#gzip on;
proxy_buffering on;
proxy_buffer_size 4k;
#proxy_buffer 32 4k;
proxy_busy_buffers_size 4k;
#proxy timeout
proxy_connect_timeout 10s;
proxy_read_timeout 15s;
proxy_send_timeout 15s;
#主要是用于设置一组可以在proxy_pass和fastcgi_pass指令中使用额代理服务器,默认负载均衡方式为轮询
upstream Tomcat_wx {
server localhost:8082;
}
#proxy_cache_path cache levels=1:2 keys_zone=wx_cache:100m inactive=5m max_size=2m;
server {
listen 80;
server_name wei-xiao.top;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
root html;
index index.htm;
proxy_pass http://Tomcat_wx;
proxy_redirect default;
#设置代理
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Range $http_range;
#proxy_cache ncache;#使用NAME这个keys_zone
#proxy_cache_valid 200 302 1h;#200和302状态码保存1小时
#proxy_cache_valid 301 1d;#301状态码保存一天
#proxy_cache_valid any 10m;#其它的保存一分钟
}
location = / {
#判断是否为手机移动端
if ($http_user_agent ~* '(iPhone|ipod|iPad|Android|Windows Phone|Mobile|Nokia)') {
rewrite . http://${host}/m/index.do break;
}
rewrite . http://${host}/index.do break;
}
location = /index.htm {
#判断是否为手机移动端
if ($http_user_agent ~* '(iPhone|ipod|iPad|Android|Windows Phone|Mobile|Nokia)') {
rewrite . http://${host}/m/index.do break;
}
rewrite . http://${host}/index.do break;
}
location = /mp/MP_verify_ZBaifoC82LoM2QR2.txt {
root html;
}
location = /mp/MP_verify_1tl94dNc9BlMbomC.txt {
root 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;
}
# 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 8086;
#listen somename:8080;
#server_name somename alias another.alias;
location / {
root E:/Deploy/ting;
index index.html index.htm;
}
}
upstream yuyi {
#server 127.0.0.1:8181;
server 127.0.0.1:8182;
#sticky_cookie_insert srv_id expires=1h domain=59.110.169.148 path=/;
}
proxy_cache_path cache levels=1:2 keys_zone=my_cache:512m inactive=5m max_size=8g use_temp_path=off;
server {
listen 8080;
#listen somename:8080;
#server_name somename alias another.alias;
location / {
root html;
index index.htm;
proxy_cache my_cache;
proxy_cache_key $scheme$proxy_host$request_uri;
proxy_cache_valid 200 5s;
#proxy_passhttp://backend_tomcat/cache$is_args$args;
proxy_pass http://yuyi;
add_header cache-status $upstream_cache_status;
proxy_redirect default;
#设置代理
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Range $http_range;
}
}
# 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;
# }
#}
}
后来发现是因为参数名写错了。
应该是:proxy_buffers 32 4k;
但很奇怪的是,前一天尝试这样的配置的时候提示了错误信息。
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/web/2022-10-10/1449.html