[英]Deploy Webpack on Nginx Subpath
I got an app running and holded on a Docker Container usign:我运行了一个应用程序并保存在 Docker 容器上:
My app works perfect under a Root Folder www.mycoolurl.com/
.我的应用程序在根文件夹
www.mycoolurl.com/
下完美运行。 But i got other app running on my root so i created www.mycoolrul.com/coolsubpath
但是我在我的根上运行了其他应用程序,所以我创建了
www.mycoolrul.com/coolsubpath
app.use(express.static(__dirname + "/dist"));
app.get("/*", function(req, res) {
res.sendFile(__dirname + "/dist/index.html");
});
upstream coolapp{
server 1.1.1.1:8000;
}
location /coolsubpath {
# Upstream
proxy_pass http://coolapp/;
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-Host $server_name;
client_max_body_size 3M;
}
My first experience with this was awful ... every request tried to mount my App, Vendor and Manifest (webpack stuff, that only need to be mounted on root).我的第一次经历很糟糕……每个请求都试图挂载我的应用程序、供应商和清单(webpack 的东西,只需要挂载在 root 上)。 So i end up doing this:
所以我最终这样做:
output: {
filename: "[name].[chunkhash].js",
path: resolve(__dirname, "../dist"),
chunkFilename: "[chunkhash].js",
publicPath: "/"
},
Now only the root will load the assets but... when i go to www.mycoolrul.com/coolsubpath
only my index.html is found and ...现在只有根会加载资产但是...当我去
www.mycoolrul.com/coolsubpath
只找到我的 index.html 并且...
The assets are looking for my ex.资产正在寻找我的前任。
www.mycoolurl.com/app.761c16f76fcba6601577.js/
instead of www.mycoolrul.com/coolsubpath/app.761c16f76fcba6601577.js/
. www.mycoolurl.com/app.761c16f76fcba6601577.js/
而不是www.mycoolrul.com/coolsubpath/app.761c16f76fcba6601577.js/
。
I tested adding React Router 4
subpath... and my Express.js
the subpath name to the .get
and .use
methods.我测试了添加
React Router 4
子路径...和我的Express.js
子路径名称到.get
和.use
方法。 Yes, it works.是的,它有效。 But now i want my subpath to be instead of
coolsubpath
like ex.但是现在我希望我的子路径不是像 ex 那样的
coolsubpath
。 mynewsupercoolsubpath
. mynewsupercoolsubpath
。 I have to rebuild and deploy the app again ?.我必须再次重建和部署应用程序吗?。
I tried rewriting the request url
but had no luck, i know the code is wrong... but i dont know how to do it我尝试重写
request url
但没有运气,我知道代码是错误的...但我不知道该怎么做
if ($http_referer ~* ^www.mycoolrul.com/coolsubpath ) {
set $request_url /coolsubpath/$1;
}
您必须在 webpack 配置中指定 publicPath 设置 - https://webpack.js.org/guides/public-path/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.