[英]Vue and Node configuration nginx
I've hosted my first Vue and Node app but I have a problem. 我已经托管了我的第一个Vue和Node应用程序,但是有问题。 I want to load Vue files on diferent port so there is less stress on node.
我想在不同的端口上加载Vue文件,以便减轻节点压力。 The problem is that with this current configuration I get this in browser:
Cannot GET /
even though when in Node router I add route with url /
I get something. 问题是在当前配置下,我在浏览器中得到了此信息:
Cannot GET /
即使在Node路由器中添加带有url的路由/
我也得到了一些东西。 But I need to load this url from vue router not from express router. 但是我需要从Vue路由器而不是从Express路由器加载此url。 Why it loads from express ?
为什么要从快递加载? This is my configuration file nginx:
这是我的配置文件nginx:
server {
listen 80;
listen [::]:80 default_server;
return 301 https://$host$request_uri;
}
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.com;
# Use the Letā€™s Encrypt certificates
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5000;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location / {
root /var/www/html/Web/dist; // Vue dist folder
}
}
In your nginx config you need to add try_files $uri $uri/ /index.html;
在您的nginx配置中,您需要添加
try_files $uri $uri/ /index.html;
to you /
location like so. 到你
/
位置。 This sends everything to your index.html file. 这会将所有内容发送到您的index.html文件。
location / {
root /var/www/html/Web/dist; // Vue dist folder
try_files $uri $uri/ /index.html;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.