Php 将url映射到子域(NGINX)
我知道这个问题一直存在,但在服务器上复制它时遇到问题 我试图做的是,当用户转到Php 将url映射到子域(NGINX),php,configuration,nginx,subdomain,configuration-files,Php,Configuration,Nginx,Subdomain,Configuration Files,我知道这个问题一直存在,但在服务器上复制它时遇到问题 我试图做的是,当用户转到medicine.example.com时,子域应该映射到example.com/sites/medicine。因此,用户看到的URL是medicine.example.com。 php是通过php剥离出来的 下面的代码给了我一个502坏网关错误 server { listen 80; listen 443 ssl; server_name medicine.example.
medicine.example.com
时,子域应该映射到example.com/sites/medicine
。因此,用户看到的URL是medicine.example.com
。
php是通过php剥离出来的
下面的代码给了我一个502坏网关
错误
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;
}
}
理想情况下,解决方案应该是基于通配符/正则表达式的,这样就可以映射的不仅仅是
medicine.example.com
。想法?我相信如果你想让浏览器中的URL保持不变,你不需要重写。所以你只需要这个(@Jack在$uri前面有一个额外的/)
$scheme应根据用户键入的内容返回http或https
server {
listen 80;
listen 443 ssl;
server_name medicine.example.com;
location / {
proxy_pass $scheme://example.com/sites/medicine$request_uri
}
这里有一个关于$uri和$request\u uri的链接。基本上,$uri不包括参数。
额外路径将自动转发到上游服务器。因此,不需要附加$request\u uri。Nginx很简单
location / {
proxy_pass http://example.com/sites/medicine
}
[edit]也不需要对上游服务器使用https,因为这会浪费ssl协商的资源。使用http更好,因为上游服务器是内部的。交通是安全的。代理通行证的值不是简单的
https://example.com/sites/medicine/$uri代码>工作(无需重写)?顺便说一句,你是在看重定向还是真的是代理?@Jack谢谢,no go不起作用。另外,$request\u uri
和$uri
变量来自哪里?我从来没有真正理解过这一点?我不想重定向url。我想保持原样,medicine.example.com
。顺便说一句,我不知道什么是代理。你的日志怎么说?问题可能出在您的proxy\u pass\u标题语句上。尝试proxy\u pass\u header Host$Host
甚至proxy\u pass\u header Host example.com
我认为您需要为cookie使用add\u header。