nginxにて下記のような設定でプロキシサーバを構築しております。
この設定でプロキシは正常に動作しております。
location /sub/host-a:10001/ { proxy_pass http://host-a:10001/; }
location /sub/host-a:10002/ { proxy_pass http://host-a:10002/; }
location /sub/host-a:10003/ { proxy_pass http://host-a:10003/; }
location /sub/host-b:10011/ { proxy_pass http://host-b:10011/; }
location /sub/host-b:10012/ { proxy_pass http://host-b:10012/; }
location /sub/host-b:10013/ { proxy_pass http://host-b:10013/; }
location /sub/host-c:10101/ { proxy_pass http://host-c:10101/; }
location /sub/host-c:10102/ { proxy_pass http://host-c:10102/; }
location /sub/host-c:10103/ { proxy_pass http://host-c:10103/; }
※例としてプロキシ先のホストとポートに規則性があるように書いていますが実際は不規則、且つプロキシ先の数も動的となっております。
上記のlocation設定を以下のように正規表現で記述できると思っているのですがプロキシされず404エラーとなってしまいます。
location ~ ^/sub/(.*)$ { proxy_pass http://$1; }
設定のどこがいけないのか教えていただけないでしょうか?
サーバの緒元は以下の通りです。
$ cat /etc/system-release
CentOS Linux release 7.4.1708 (Core)
$ rpm -qa | grep nginx
nginx-mod-http-geoip-1.12.2-1.el7.x86_64
nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
nginx-filesystem-1.12.2-1.el7.noarch
nginx-mod-stream-1.12.2-1.el7.x86_64
nginx-mod-http-perl-1.12.2-1.el7.x86_64
nginx-1.12.2-1.el7.x86_64
nginx-all-modules-1.12.2-1.el7.noarch
nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
nginx-mod-mail-1.12.2-1.el7.x86_64
回答3件
あなたの回答
tips
プレビュー