当请求后台的响应时间过长时,前端会出现报错。这里修改调整Nginx配置文件参数以解决这个问题。
目录
1.配置文件(nginx.conf)
总结
配置文件(nginx.conf)
代码如下(示例):
server {listen 80;server_name 127.0.0.1;location / {root html;index index.html index.htm;try_files $uri $uri/ /index.html;expires -1;if_modified_since off;add_header Last-Modified "";add_header Cache-Control no-cache;etag off;#设置Nginx从后端服务器读取响应的超时时间proxy_read_timeout 600s;#设置Nginx发送请求到后端服务器的超时时间proxy_send_timeout 600s;#设置Nginx建立与后端服务器连接的超时时间proxy_connect_timeout 600s;}location /prod-api/ {proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://127.0.0.1:8070/;}}
总结
通过配置proxy_read_timeout、 proxy_send_timeout、 proxy_connect_timeout参数,使得前端等待后台响应的时间增长,从而解决超时问题。