求教nginx配置转发

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/ 应该是会转发到 https://www.humanchan.me/api/ 但是一直不成功,是我写错了么,还是应该怎么写

阅读 2.5k
1 个回答

上面这个server针对api.humanchan.me这个域名,所以下面写的/api/那块没什么用,再说现在这个配置对于api.humanchan.me都会301到www.humanchan.me/api/,有什么问题吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题