Home  >  Q&A  >  body text

Ask for advice on nginx configuration forwarding

server {
listen 443;
server_name localhost api.humanchan.me;
ssl on;
root html;
index index.html index.htm;

if ($http_host ~ "^api.humanchan.me$") {
rewrite ^(.*) https://www.humanchan.me/api/$1 permanent;
}

location ^~ /api/ {

proxy_pass http://127.0.0.1:7001;
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_set_header X-Forwarded-Proto $scheme;
}

}

https://api.humanchan.me/ should be forwarded to https://www.humanchan.me/api/ but it has been unsuccessful. Did I write it wrong or how should I write it

仅有的幸福仅有的幸福2714 days ago507

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-16 17:09:02

    The server above targets the domain name api.humanchan.me, so the /api/ written below is of no use. Besides, this configuration now will 301 to www.humanchan.me/api/ for api.humanchan.me. What’s the problem? ?

    reply
    0
  • Cancelreply