1

我正在尝试使用@nuxt/pwa starter-template设置Nuxt应用程序以在共享主机上进行服务器端渲染。但是我的 Nuxt 应用程序在“ http://localhost:50000 ”上运行。我试图通过在.htaccess 中重写规则来显示来自“ http://example.com ”的正在运行的应用程序。

当尝试访问“ http://example.com ”时,它显示 404。没有“索引 (/)”路由,其他所有路由都可以。即使从任何其他路线来到“索引(/)”路线也是可以的。仅在尝试直接加载“/”路由时显示 404。

例如:

http://example.com不工作

http://example.com/contact工作正常

*** 在 Github 上已经有一个和我一模一样的问题:https ://github.com/nuxt/nuxt.js/issues/2625 但我从那里找不到任何有用的东西。

这是我正在使用的.htaccess文件。--

Options +FollowSymLinks 
<IfModule mod_rewrite.c>

RewriteEngine on

RewriteRule ^(.*) http://127.0.0.1:50000/$1 [P,L]

</IfModule>

有人可以帮我解决这个问题吗???提前致谢!

4

3 回答 3

1

这个答案似乎有点晚了,但我只在github中找到它,并希望帮助任何发现这个主题的人遇到同样的问题。

这个 htaccess 对我有用,当我刷新并且导航正常工作时,它会正常加载 index.vue 页面。

将 my-domain 替换为您的域。

RewriteEngine on

# Forcing all incoming requests to HTTPS. 
# HTTPS is required for PWA. If you don't want PWA feature you can deisable next 2 lines

RewriteCond %{HTTP_HOST} ^my-domain.com.br$
RewriteRule "(.*.(jpg|gif|png|svg|js|css|woff2))$" "http://127.0.0.1:3000/$1" [P,NC]
RewriteRule ^(.*) "http://127.0.0.1:3000/$2" [P,L]
于 2019-06-26T14:03:20.620 回答
0

使用我的 .htaccess 代码:

RewriteRule ^index.html.var$ http://127.0.0.1:3000/ [P]
RewriteRule ^(.*) http://127.0.0.1:3000/$1 [P]

这个问题也困扰了我很久。我添加了 _index.vue 动态 vue-router 并且,

validate ({params}) {
  console.log (params.index);
}

终端输出“index.html.var”。所以我在想,当我们访问主页时,Apache发送了一个代理,但是nuxt.js收到的请求URL不是“/”而是“index.html.var”。

于 2020-04-24T02:46:44.717 回答
-1

重写引擎开启

强制所有传入请求为 HTTPS。

PWA 需要 HTTPS。如果你不想要 PWA 功能,你可以取消下 2 行

RewriteCond %{HTTP_HOST} ^my-domain.com.br$ RewriteRule "(.. (jpg|gif|png|svg|js|css|woff2))$" " http://127.0.0.1:3000/ $1" [P,NC] RewriteRule ^(. ) " http://127.0.0.1:3000/ $2" [P,L]

为我工作。

于 2020-03-28T16:47:04.343 回答