我正在做我的老项目,一个自定义的ShareX上传程序,但我遇到了一个服务器(nodejs)返回的问题。
当应该返回https://example.com/u/blablah.png时,它返回https://localhost/u/blablah.png
我在请求服务器上传图像时获取req.hostname,它在请求上传(post)的rawHeaders上返回localhost:myport。我开始假设这是我的NGiNX配置是如何设置的,但如果有人能指出我的假设是否正确的话,我希望有人能指出这是我的NGiNX而不是我的代码。
我的NGiNX配置:
server {
listen 80;
listen [::]:80;
server_name example.com;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
location ~ /\.(?!well-known)
{
deny all;
}
location / {
proxy_pass http://localhost:1337/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
}我在NGiNX上使用Cloudflare,UAM设置为Essentially Off,所以我知道它是100%不是Cloudflare这一端。
发布于 2021-06-14 20:57:18
我弄明白了,对于以后可能遇到这个问题的任何人,这里是我是如何解决它的:
server {
listen 80;
listen [::]:80;
server_name example.com;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
location ~ /\.(?!well-known)
{
deny all;
}
location / {
proxy_set_header Host $host;
proxy_pass http://localhost:1337/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
}我必须添加下面的代理头proxy_set_header Host $host;,在添加它现在给定域之后。
https://stackoverflow.com/questions/67970391
复制相似问题