我正在运行nGINX服务器。我想从传入的请求中读取自定义HTTP标头,并将其重定向到不同的应用程序服务器。我确实搜索过类似的问题,但发现编写自定义标题而不是如何阅读..
如果使用此设置标头 - > “version = Version 1.0”然后它应该重定向不同的应用程序(比如uwsgi_pass x.x.x.x:80)
如果设置为“version = Version 2.0”,那么它应该重定向到(uwsgi_pass x.x.x.x:99)
我在我的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;
}
}
我重启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
答案 0 :(得分:1)
假设您以此形式设置自定义标头:
version: Version 1.0
然后你就可以这样配置nginx:
location / {
if ($http_version ~ 'Version 1.0') {
uwsgi_pass localhost:8888;
}
if ($http_version ~ 'Version 2.0') {
uwsgi_pass localhost:9999;
}
}