Scene description
A project was recently deployed. Because it is compatible with IE8, the front and back ends need to be deployed to a site. The nginx configuration is as follows:
server {
listen 80;
server_name www.aaa.ink;
client_max_body_size 1000M;
client_body_timeout 20s;
client_header_timeout 10s;
send_timeout 30s;
ssl_protocols TLSv1.2;
charset utf-8;
location ^~ /api/ {
proxy_pass http://127.0.0.1:8080/api/;
}
location ~/(.*)$ {
root /usr/local/nginx/ttm;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Swagger is used as the interface document in the background. After the project is started, the site can be accessed normally, but an error will be reported when testing the interface in swagger. The error prompt is typeerror: failed to fetch
Problem analysis
Analysis shows that swagger’s actual request address becomes http://127.0.0.1:8080/api/ , it’s not what we actually do http://www.aaa.ink/api/ Interface address. It is found that swagger will obtain a server address according to the user’s request. Due to the use of nginx reverse proxy, swagger obtained the intranet address we configured, resulting in the request unable to respond normally.
Problem solving
location ^~ /api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass http://127.0.0.1:8080/api/;
}
Set the forwarding of background items to the request header so that swagger can get the real address. The problem can be solved.
Read More:
- How to Solve Swagger error: IllegalStateException
- How to Solve Swagger Always Displays “basic-error-controller” Issue
- [Solved] Springboot integrate swagger error: failed to start bean ‘documentationpluginsbootstrapper‘
- [Solved] swagger Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullP
- Springboot Integrate Swagger2 Error: Failed to start bean ‘documentationPluginsBootstrapper‘;
- [Solved] Springboot integrate swagger error: Failed to start bean ‘documentationPluginsBootstrapper‘
- Tensorflow Error TypeError: Fetch argument XXXX has invalid typeXXXX,must be a string or Tensor
- How to Solve Image Upload Error: Uncaught (in promise) DOMException: Failed to execute ‘put‘ on ‘IDBObjectStore‘
- How to Solve “413 request entity too large” Error
- How to Solve zuul Forwarding error (No Retrayable)
- How to Solve Linux connecte to the old version of SQL Server Error
- How to Solve Error: call_and_retry_last allocation failed – javascript heap out of memory
- How to Solve Error: Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
- [Solved] Springboot Error: swagger-UI/index.html Access Error 404
- How to Solve c3p0 error (Cause & Solution)
- How to Solve Log4j 2.5 upgrade to 2.15 error
- How to Solve IntelliJ IDEA Error: Cannot determine path to ‘tools.jar‘ library for 17 (C:\Program Files\Java\jd…
- How to Solve ERROR: Java 1.7 or later is required to run Apache Drill
- How to Solve nacos Startup Error and Connect to MYSQL
- How to Solve IBM MQ Connect Error Code 2035