将url映射到子网域(NGINX)

我知道这个问题之前已经问过,但我有麻烦复制它在我的服务器上。

我想要做的是当用户去medicine.example.com ,该子域应该映射到example.com/sites/medicine 。 所以用户看到的URL是medicine.example.com 。 index.php通过php被剥离。

理想的情况下,解决scheme将是一个基于通配符/正则expression式,这样不仅medicine.example.com可以映射到url。

下面的代码给了我一个502 bad gateway错误。

 server { listen 80; listen 443 ssl; server_name medicine.example.com; location / { rewrite ^([^.]*[^/])$ $1/ permanent; proxy_pass_header Set-Cookie; proxy_pass https://example.com/sites$request_uri; } } 

你不是真的想代理请求到同一个networking服务器,它需要更多的开销。 我将为这两个域configuration单个虚拟主机,并使用if语句来仅重写子域的请求。

 server { server_name example.com medicine.example.com; if ($host = "medicine.example.com") { rewrite . /sites/medicine$request_uri; } ... }