Home > Article > Operation and Maintenance > How to solve nginx error 404Not Found when accessing dynamic interface
Designer used Ant Design Vue and JFinal framework to develop the front-end and back-end respectively, and created a recruitment background adjustment system. Try to deploy the project to the server, but the 404 Not Found error continues to appear when accessing externally
Position the error as: not found Dynamic interface, but I don’t know if there is a problem in the project or after nginx proxy.
Therefore, the interface of the project itself and the interface after nginx proxy must be tested separately.
First test the interface within the project:
Enter the command on the ubuntu side: curl http://localhost:port/xxx/xxx
My interface here is : curl http://localhost:20294/sys/login
Running result:
It means that there is no problem with the interface in my project .
Test the interface after nginx proxy again:
Enter the command in ubuntu
curl http://localhost:8080/api/user/login
Running result:
Here it says that the interface cannot be found, indicating that the problem lies with the proxy server nginx, so we need to modify the nginx configuration file.
Following the suggestions of other blogs, I added a slash to this place in the nginx configuration
After restarting the server, it still didn’t work.
When I didn’t know what to do, I suddenly discovered that there were two nginx·····## in my server #I am wondering if it is because there are two nginx and the modified configuration file is not the nginx I started. So I replaced all nginx configuration files with my original configuration files and restarted. Still not working
ps aux|grep nginx #查看nginx进程 kill -9 进程号 #杀死上一步中查询到的nginx(进程号在第二列) find / -name nginx #找到nginx的文件地址 rm -rf xxx #删除nginx所有文件Finally use weget to install the new nginx, and then install it according to the original installation steps. After modifying the configuration file, run curl to access the dynamic interface, and suddenly everything is fine! My nginx configuration file is posted below:
user root; #user nobody; worker_processes 4; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server_names_hash_bucket_size 128; client_header_buffer_size 32k; underscores_in_headers on; large_client_header_buffers 4 32k; client_max_body_size 50m; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nopush on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; tcp_nodelay on; #gzip on; ###################################################### ############# 麻雀配置地址 ########### ###################################################### server { listen 8080; server_name somename; location /api/ { proxy_pass http://0.0.0.0:20294/; #映射到本地端口。 proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 200m; proxy_connect_timeout 600; proxy_read_timeout 600; } location / { root /root/project-template/config/static; try_files $uri $uri/ @router; index index.html; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 200m; proxy_connect_timeout 600; proxy_read_timeout 600; } location @router { rewrite ^.*$ /index.html last; } } }It should be noted that when configuring dynamic access api, remember to add a slash at the end
The above is the detailed content of How to solve nginx error 404Not Found when accessing dynamic interface. For more information, please follow other related articles on the PHP Chinese website!