gpt4 book ai didi

django - nginx子域和域重写w代理pass

转载 作者:行者123 更新时间:2023-12-04 01:33:59 25 4
gpt4 key购买 nike

我需要这两种类型的重写:
subdomain.domain.com => domain.com/website/subdomainotherdomain.com => domain.com/userdomain/otherdomain.com
我的问题是我想让用户看到 subdomain.domain.com , 和 otherdomain.com ,而不是重定向版本。我当前在 nginx 中的重写有效,但用户的 URL 显示了重写,我希望这对用户透明,有什么想法吗?:

upstream domain_server { server localhost:8000 fail_timeout=0; }     

server {
listen 80;
root /var/www/domain.com;

server_name domain.com ~^(?<subdomain>.*)\.domain\.com$ ~^(?<otherdomain>.*)$;
if ( $subdomain ) {
rewrite ^ http://domain.com/website/$subdomain break;
}
if ( $otherdomain ) {
rewrite ^ http://domain.com/userdomain/$otherdomain break;
}

location / {
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
if (!-f $request_filename) {
proxy_pass http://domain_server;
break;
}
}

}

最佳答案

使用 nginx,您根本不需要重写。

upstream domain_server { server localhost:8000 fail_timeout=0; }

proxy_set_header Host domain.com;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;

server {
listen 80 default_server;

location / {
proxy_pass http://domain_server/userdomain/$http_host;
}
}

server {
listen 80;
server_name domain.com;

root /var/www/domain.com;

location / {
try_files $uri @backend;
}

location @backend {
proxy_pass http://domain_server;
}
}

server {
listen 80;
server_name ~^(?<subdomain>.+)\.domain\.com$;

location / {
proxy_pass http://domain_server/website/$subdomain$request_uri;
}
}
  • http://nginx.org/r/proxy_pass
  • http://wiki.nginx.org/IfIsEvil
  • http://wiki.nginx.org/Pitfalls
  • http://nginx.org/en/docs/http/converting_rewrite_rules.html
  • 关于django - nginx子域和域重写w代理pass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10541160/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com