我正在 AWS 上使用 Node JS + React + NGINX 设置 Web 应用程序 然后当我想访问 url/auth
它返回给我一些 HTML 代码,而不是像我想要的那样的 JSON 我在 LOCALHOST 上测试了代码,它工作正常
我尝试设置文件夹权限,因为我认为用户权限可能是问题
我还尝试在 Nginx.conf 上编辑一些内容
下面是我的 nginx 的 app.conf
upstream webapp{
server 127.0.0.1:3018;
}
server_names_hash_bucket_size 64;
server_names_hash_max_size 512;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 127.0.0.1;
server_name_in_redirect off;
if ($http_x_forwarded_proto = 'http'){
return 301 https://$host$request_uri;
}
location / {
root /home/website/client/build;
try_files $uri /index.html;
log_not_found off;
access_log off;
}
#error_page 405 =200 $uri;
if ( $http_user_agent ~* (nmap|nikto|wikto|sf|sqlmap|bsqlbf|w3af|acunetix|havij|appscan) ) {
return 403;
}
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block;";
add_header Strict-Transport-Security "max-age=2592000; includeSubDomains" always;
}
action {…}
payload: Object { isAuth: false, error: true }
type: "auth_member"
我期望输出代码像这样 但网络却给了我其他东西
最佳答案
您必须定义要代理的上游位置:
# this is an example you can modify the path on as you get it
location /api {
proxy_pass http://webapp;
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;
}
关于node.js - 错误 : Request failed with status code 405 , 有效负载返回 HTML,而不是预期的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58521997/