How to deploy Nuxt SSR with mod_rewrite in a sub folder?

风格不统一 提交于 2019-12-11 15:56:48

问题


Currently I'm running a Django based website. I want to replace my "/admin/" area with a Vue/Nuxt build version but keep the rest of my website for now.

To serve my files I use Apache2 with mod_rewrite enabled. My Nuxt server is running on localhost:3000.

In my .htaccess I wrote this line to proxy /admin/ to the Nuxt Server

RewriteRule ^admin/(.*) http://localhost:3000/$1 [P]

If I access www.example.com/admin/ I see the output of my Nuxt project. But all resources are not loaded because the paths are wrong.

Instead of www.example.com/admin/.nuxt/... Nuxt is "looking" to www.example.com/.nuxt/

How can I change this?


回答1:


I finally solved the problem on my own:

Solution

nuxt.config.js

  router: {
    base: "/myapp/"
  },

.htaccess

RewriteRule ^myapp/(.*) http://localhost:3000/myapp/$1 [P]
RewriteRule ^_nuxt/(.*) http://localhost:3000/_nuxt/$1 [P]


来源:https://stackoverflow.com/questions/56806714/how-to-deploy-nuxt-ssr-with-mod-rewrite-in-a-sub-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!