Nginx URL masking to a different domain

后端 未结 2 509
野性不改
野性不改 2020-12-25 08:59

There\'s a few similar questions on SO, but none exactly mine, and I\'ve had no luck trying to adapt their answers so far.

I want to map the URL http://sub.exa

2条回答
  •  时光说笑
    2020-12-25 09:24

    I did like this:

    server {
        listen 80;
        listen [::]:80;
        listen 443 http2 ssl;
        listen [::]:443 http2 ssl;
    
        server_name domain1;
    
        if ($request_method ~* OPTIONS|GET|HEAD) {
            return 301 https://domain2$request_uri;
        }
    
        location ~* api {
            proxy_pass https://domain2$request_uri;
        }
    }
    

    Because post-requests will cause a 405 error when redirecting.

提交回复
热议问题