关于nginx配置的一些
nginx配置
1.解决请求头部分内容缺失问题
由于是nginx代理转发,所以不标准的tcp报文会被截掉一部分发不出去,所以加了一句
underscores_in_headers on;
解决请求头部分内容缺失问题
来自 https://blog.csdn.net/caohl04/article/details/88792936
#user nobody;
worker_processes 10;
error_log /usr/local/nginx/logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/nginx/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;
underscores_in_headers on; '插入部分'
server {
listen 8900;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.html;
}
被nginx截掉的报文:
POST /httpproxy HTTP/1.0
Host:
Connection: close
Content-Length:
cache-control: no-cache
Postman-Token:
User-Agent: PostmanRuntime/7.6.0
Accept: */*
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------138310851990932224697531
----------------------------138310851990932224697531
Content-Disposition: form-data; name=""
----------------------------138310851990932224697531--
调整之后完整的报文(部分字段信息已手动清理):
POST /httpproxy HTTP/1.1
a_rtime:
a_sign:
a_rid:
a_sid:
cache-control: no-cache
Postman-Token:
User-Agent: PostmanRuntime/7.6.0
Accept: */*
Host:
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------694089711644805398248924
content-length:
Connection: keep-alive
----------------------------694089711644805398248924
Content-Disposition: form-data; name=""
----------------------------694089711644805398248924--
2.location配置详细解释
location = / {
#规则A
}
location = /login {
#规则B
}
location ^~ /static/ {
#规则C
}
location ~ \.(gif|jpg|png|js|css)$ {
#规则D,注意:是根据括号内的大小写进行匹配。括号内全是小写,只匹配小写
}
location ~* \.png$ {
#规则E
}
location !~ \.xhtml$ {
#规则F
}
location !~* \.xhtml$ {
#规则G
}
location / {
#规则H
}
那么产生的效果如下:
访问根目录/, 比如http://localhost/ 将匹配规则A
访问 http://localhost/login 将匹配规则B,http://localhost/register 则匹配规则H
访问 http://localhost/static/a.html 将匹配规则C
访问 http://localhost/a.gif, http://localhost/b.jpg 将匹配规则D和规则E,但是规则D顺序优先,规则E不起作用, 而 http://localhost/static/c.png 则优先匹配到 规则C
访问 http://localhost/a.PNG 则匹配规则E, 而不会匹配规则D,因为规则E不区分大小写。
访问 http://localhost/a.xhtml 不会匹配规则F和规则G,
http://localhost/a.XHTML不会匹配规则G,(因为!)。规则F,规则G属于排除法,符合匹配规则也不会匹配到,所以想想看实际应用中哪里会用到。
访问 http://localhost/category/id/1111 则最终匹配到规则H,因为以上规则都不匹配,这个时候nginx转发请求给后端应用服务器,比如FastCGI(php),tomcat(jsp),nginx作为方向代理服务器存在。
来自https://www.cnblogs.com/jpfss/p/10418150.html