我有两台运行nginx的服务器:
服务器1上有一系列项目 服务器2具有新的Vue / Nuxtjs(节点)
在服务器1上,我已为运行基于节点的应用程序的服务器2的静态IP设置了proxy_pass
。因此,目标是让用户在浏览网站时只看到http://domain.tld/folder
,http://domain.tld/folder/login
等
服务器1:
location /folder/ {
proxy_pass http://200.1.1.1/; // IP of server 2
}
服务器2:
location / {
proxy_pass http://localhost:3000;
}
这部分起作用,但所有资产均为404。点击链接时,浏览器访问http://domain.tld/login
[更新] 完整的服务器2 nginx配置(注释了一些东西以避免冲突):
server {
listen 80;
listen 443;
# set path to your project dir
set $root_path /root/app;
# static content directory
root $root_path/client/nuxt-dist/dist;
# proxy to nuxt renderer
try_files $uri $uri/ @nodeproxy;
location @nodeproxy {
proxy_pass http://localhost:3000;
}
# entry point for API server,if you have one
location /api {
proxy_pass http://localhost:3001;
client_max_body_size 3m;
}
# serve nuxt bundle with max cache life. Only compatible with nuxt 2.*
# location ~^\/_nuxt(.*)$ {
# alias $root_path/client/.nuxt/dist/client/$1;
# gzip on;
# gzip_comp_level 6;
# gzip_vary on;
# gzip_types text/css application/json application/javascript text/javascript application/x-font-ttf font/opentype;
# expires max;
# }
# serve static content
location ~* \.(js|jpg|jpeg|txt|png|css|pdf|ico|map)$ {
gzip_static on;
expires 30d;
}
# refirect from /path/ to /path
# rewrite ^/(.*)/$ /$1 permanent;
}