nginx subdomain and domain rewrite w proxy pass

后端 未结 1 1470
一整个雨季
一整个雨季 2021-01-31 06:09

I need these two types of rewrites:

subdomain.domain.com => domain.com/website/subdomain

otherdomain.com => domain.com/userdomain/otherd

相关标签:
1条回答
  • 2021-01-31 06:53

    With nginx you don't need rewrites at all.

    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
    0 讨论(0)
提交回复
热议问题