如何将VUE JS应用托管到NGNIX服务器?
通过基本的NGINX配置托管应用程序(下面的示例配置),但这对于静态Web应用程序是有意义的。如何为VUE JS应用程序设置,我必须在其中运行NPM运行服务以启动应用程序。我只是构建应用程序,然后使用NPM运行构建,然后在某个地方复制构建/DIST文件夹。我在RHEL 8上尝试此操作。我的包装。JSON文件看起来像这样
{
"name": ....
....
"scripts":{
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
...
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
going through basic nginx configuration to host an app ( sample config below) , but this makes sense for a static web app. how to set up for a vue js app, where i have to run the npm run serve to start app. do i just build the app , with npm run build and then copy the build/dist folder somewhere . i am trying this on RHEL 8. my package.json file looks like this
{
"name": ....
....
"scripts":{
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
...
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样主持,效果很好。
在
/etc/nginx/nginx.conf
中:您可以看到,所有编译的VUE文件我存储在
/var/var/www/mysite-folder
中I host like this, and it works pretty fine.
In
/etc/nginx/nginx.conf
:And as you can see, all compiled Vue files I store in
/var/www/mysite-folder