【发布时间】:2021-01-16 03:26:21
【问题描述】:
我正在尝试将帮助 URL 从 example.com/help 重写为 help.example.come。
我尝试了很多配置 nginx 的方法,但是当我请求 example.com/help 时,会出现片刻内容,然后它会重定向到带有 help.example.come url 的主页。
我在工作中使用了 nuxtjs v2.13.3 和 nginx。这是我的 nginx 配置文件:
- nuxtjs 服务器块
server {
listen 80;
index index.html;
root /var/www/site/dist/;
server_name example.come;
location / {
proxy_pass http://127.0.0.1:3000;
}
# help redirecting...
location ~ ^/help/(.*)$ {
return 301 $scheme://help.example.come/$1;
}
}
- 子域服务器块
server {
listen 80;
server_name help.example.come;
location / {
proxy_pass http://127.0.0.1:3000/help/;
}
location /_nuxt/ {
rewrite /help/(.*) /$1;
proxy_pass http://127.0.0.1:3000/_nuxt/;
}
location ~* \.(jpg|jpeg|gif|png|ico)$ {
rewrite ^/_nuxt(/.*) $1;
root /var/www/site/dist/;
expires 30d;
}
}
【问题讨论】:
-
只是为了清楚。您想将 example.com/help 上的用户初始请求重定向到 help.example.com,然后将其代理给您的后端 nuxt???我说的对吗?
-
是的@TimoStark。实际上我为nuxt设置了一个特定的端口。
标签: php nginx nuxt.js subdomain nginx-reverse-proxy