Redirect to metadata problem?

I used the project template ServiceStatck ASP.NET Empty to build a website, and config a port 5004, Like http://192.168.2.221:5004/metadata, It works fine. If I used nginx in the front with a domain name, the domain name like api.domain.com, if I visit the url , it will redirect to api.domain.com:5004/metadata, it will no result , If I visit api.domain.com/metadata , it works fine. but in this page , like ‘Swagger UI’ url is http://api.domain.com:5004/swagger-ui/ , how to solve it ?
My Config is below, and have update the servicestack to 4.5.12 .

  SetConfig(new HostConfig
        {
            DebugMode = true,
            DefaultContentType = MimeTypes.Json 
       });

You need to setup nginx as a reverse proxy properly so that it rewrites the internal urls to use its external urls. Here are the docs for nginx proxy_pass.

I have set nginx as a reverse proxy, like mvc website works fine, like
http://api.domain.com/todos , it also works fine, only the metadata have the problem,

my nginx config is

 server {
			listen  80;
			server_name  api.domain.com;
			access_log  logs/api.access.log; 
			error_log  logs/api.error.log;

			location / {
			 proxy_pass         http://api;
			deny 59.125.172.0/24;
			#proxy_redirect     off;
			proxy_set_header   Host             $host;
			proxy_set_header   X-Real-IP        $remote_addr;
			proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
			proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
			proxy_max_temp_file_size 0;
			proxy_connect_timeout      90;
			proxy_send_timeout         90;
			proxy_read_timeout         90;
			proxy_buffer_size  128k;
			proxy_buffers   32 32k;
			proxy_busy_buffers_size 128k;
			proxy_temp_file_write_size 128k;
			}
		}
upstream api {
	 server 192.200.54.135:5004;
	 keepalive 64;
	}

Your nginx isn’t setup up properly and you haven’t followed my links, please read the docs I linked to. When configured properly nginx does the rewriting of urls.

But if you prefer you can also make ServiceStack rewrite the Urls by overriding ResolveAbsoluteUrl() and returning the external Absolute Url.

I have followed the your links, and changed the nginx config like below, it also behave like before.

 server {
			listen  80;
			server_name  api.domain.com;
			access_log  logs/api.access.log; 
			error_log  logs/api.error.log;
		       set $upstream 192.200.54.135:5004;
			location / {
			deny 59.125.172.0/24;
			proxy_pass_header Authorization;
			 proxy_pass http://$upstream;
			 proxy_set_header Host $host;
			 proxy_set_header X-Real-IP $remote_addr;
			 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			 proxy_http_version 1.1;
			 proxy_set_header Connection "";
			 proxy_buffering off;
			 client_max_body_size 0;
			 proxy_read_timeout 36000s;
			 proxy_redirect off;
			}
		}

your said overriding ResolveAbsoluteUrl(), how to code it returning the external Absolute Url?

I found in the topic API Metadata when behind Nginx proxy pass

your reply is

You can configure it with a Config.WebHostUrl, e.g:

SetConfig({
    WebHostUrl = "http://local.mydomain.com/api"
});

I set the config like below , it works fine.

SetConfig({
    WebHostUrl = "http://api.domain.com"
});