如何使用NGINX将所有请求redirect到子path?

应用程序,问题和目标的概述。

该应用程序由微服务networking组成,包装在单独的Docker容器中。 这些容器是Django,Postgres,Nodejs(+ Socket.io)和Nginx + Angular2(静态文件)。 Nginx目前具有特定的文件path,并将所有其他请求路由到Angular2应用程序,然后它有自己的路由器。

目前,应用程序可以直接从根目录提供,但必须移到子目录中。 该地址随后将包含该目录的新path。

所以它部署到… http://host ,但不与http://host/path ,因为在微服务中的所有请求都得到路由NGINX逆向代理。

我怎样才能使用NGINX重写/redirect追加/path的URL,以便它可以从子目录服务,但NGINX仍然知道这些位置仍然存在于根级别?

我的301尝试

  location = / { root /www/ng; try_files $uri $uri/ /index.html; return 301 http://$host/pot; } 

在这里,我做了301redirect捕获所有位置。 它适用于这个捕获所有,但是当将301添加到静态位置时,redirect不起作用。 301是最好的解决scheme吗? 我将如何redirect静态位置?

原始的NGINX conf文件

 server { listen 80; client_max_body_size 10M; root /www/data; location /static { alias /var/www/static; } location /media { alias /var/www/media; } location ~* ^/(api|admin) { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://django:8000; } location /gateway { proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://nodejs:3000; } location = / { root /www/ng; } location / { try_files $uri $uri/ @ng; } location @ng { root /www/ng; try_files $uri $uri/ /index.html; } error_page 403 /403.html; error_page 404 /404.html; error_page 500 502 503 504 /500.html; }