nginxで違うportのprocessにproxyする

内部のプロセスにproxy

:8000で動いているSimpleHTTPServerにproxy

python -m SimpleHTTPServer 8000 で動かしたhttp serverに/python/でアクセスした場合にproxyするようにする設定。

/etc/nginx/conf.d/proxyserve.conf

server {
   listen 80 default_server;
   location /python/ {
       proxy_pass http://localhost:8000/;
   }
}

注意点としてはproxy_passに渡す引数が以下の2つの場合で結果が変わる

前者の場合は http://localhost:80/python/ => http://localhost:8000/python/ というように変換される 後者の場合は http://localhost:80/python/ => http://localhost:8000/ というように変換される

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass