[英]nGINX read Header & Pass it to different Application Server
I have an nGINX server running. 我正在运行一个nGINX服务器。 I want to read custom HTTP Header from the incoming Request and redirect it to different application server. 我想从传入的请求中读取自定义HTTP标头,并将其重定向到其他应用程序服务器。 I did search for similar questions but found for writing custom headers but not how to read.. 我确实搜索了类似的问题,但发现是为了编写自定义标头,而不是如何阅读。
if a header is set with this -> "version = Version 1.0" then it should redirect different application (say uwsgi_pass xxxx:80) 如果使用此标题设置了->“ version = Version 1.0”,则它应该重定向其他应用程序(例如uwsgi_pass xxxx:80)
if it is set as "version = Version 2.0" then it should redirect to (uwsgi_pass xxxx:99) 如果将其设置为“版本=版本2.0”,则应重定向到(uwsgi_pass xxxx:99)
I tried in my nginx.conf file 我在我的nginx.conf文件中尝试过
server{
listen 80;
server_name xyz.com;
if ($http_version ~ 'Version 1.0') {
proxy_pass http://192.168.0.116:99/calc;
}
if ($http_version ~ 'Version 2.0') {
proxy_pass http://192.168.0.116:99;
}
location /hello {
proxy_pass http://192.168.0.116:99/calc;
}
}
I'm getting error when I restart my nGINX 重新启动nGINX时出现错误
nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/nginx.conf:19
nginx: configuration file /etc/nginx/nginx.conf test failed
Suppose you set a custom header in this form: 假设您以这种形式设置自定义标头:
version: Version 1.0
Then you can configure nginx like in this way: 然后,您可以按以下方式配置nginx:
location / {
if ($http_version ~ 'Version 1.0') {
uwsgi_pass localhost:8888;
}
if ($http_version ~ 'Version 2.0') {
uwsgi_pass localhost:9999;
}
}
Reference: http://wiki.nginx.org/HttpCoreModule#.24http_HEADER 参考: http : //wiki.nginx.org/HttpCoreModule#.24http_HEADER
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.