gpt4 book ai didi

ajax - 使用 Nginx 作为代理,ajax 请求每隔一个请求得到 405

转载 作者:行者123 更新时间:2023-11-28 22:51:11 27 4
gpt4 key购买 nike

我正在使用 nginx 来分离静态和动态内容,这是我的 nginx 配置:



#user nobody;
worker_processes 1;

#error_log logs/error.log;
error_log /usr/local/var/logs/nginx/error.log notice;
#error_log logs/error.log info;

pid /usr/local/var/logs/nginx/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr:$remote_port - [$request_method] [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';

access_log /usr/local/var/logs/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

upstream tomcat_backend {
server localhost:8090;
}

server {
listen 9797;
server_name localhost;
server_name_in_redirect off;
access_log /usr/local/var/logs/nginx/test.access.log main;
error_log /usr/local/var/logs/nginx/test-error.access.log debug;
location ~ \.(jpg|png|js|ico|html|gif|css|map)$ {
root /path/to/static;
}
location ^~ /api/ {
access_log /usr/local/var/logs/nginx/nginx-location.access.log main;
error_log /usr/local/var/logs/nginx/nginx-location-error.access.log debug;
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_set_header X-Request-Time $msec;
proxy_redirect off;
proxy_set_header Host $host;
proxy_pass http://tomcat_backend;
#proxy_set_header X-Request-Id $request_id;
}
location / {
root /path/to/static;
index index.html;
if (!-e $request_filename) {
rewrite ^/(.*) /index.html last;
}

}
}
include servers/*;
}

有时tomcat可以获取到请求并正确响应,有时nginx只是直接返回405,没有事件转发给tomcat

这是 chrome 的控制台,它总是遵循这样的模式,405, 401, 405, 401 ...,它显示 401 是因为我故意输入错误的密码,这意味着请求已转发给 tomcat: enter image description here

我发现如果我使用 node.js 作为后端(只是一个代理服务器),一切正常,不再是 405。

最佳答案

好吧,终于找到原因了。

有另一个进程正在监视同一个端口。

但是两个进程使用同一个端口是有线的

关于ajax - 使用 Nginx 作为代理,ajax 请求每隔一个请求得到 405,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39158346/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com