在家里电脑(家宽) 0.0.0.0:5000 绑定了一个服务,并用 frp 映射到了远程云主机的 127.0.0.1:5001
现在想要在云电脑上用 nginx 反代把 5001 暴露到公网,再绑定一个域名,这样就可以直接访问家里的服务。nginx 是用宝塔挂的。
遇到问题是,域名解析、反代和上证书看似都成功了。访问 home.example.com 是能正确接收到该服务根目录的 html 的,但是网页无法渲染,因为类似 home.example.com/assets/main.js 这种路由全都会跳 404 ,这是咋回事呢?(检查了一下云主机本地 wget 127.0.0.10:5001/assets/main.js 是可以正常获取文件的,frp 部分应该是工作正常)
网站完整配置:
server
{
listen 80;
listen 443 ssl http2;
server_name home.example.com;
root /www/wwwroot/home.example.com;
#SSL-START SSL 相关配置,请勿删除或修改下一行带注释的 404 规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/home.example.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/home.example.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
#SSL-END
#PHP-INFO-START PHP 引用配置,可以注释或修改
include enable-php-00.conf;
#PHP-INFO-END
#REWRITE-START URL 重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/home.example.com.conf;
#REWRITE-END
location / {
proxy_pass http://127.0.0.1:5001/;
proxy_http_version 1.1;
client_max_body_size 100M;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请 SSL 证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log /dev/null;
}
access_log /www/wwwlogs/home.example.com.log;
error_log /www/wwwlogs/home.example.com.error.log;
}