nginx訪問動態(tài)接口報錯404Not Found問題解決
問題描述
計設(shè)做了一套招聘背調(diào)系統(tǒng),前后端分別使用了Ant Design Vue與JFinal框架。想要將項目部署到服務(wù)器上,但是外部訪問一直報錯404Not Found
解決思路
把錯誤定位為:找不到動態(tài)接口,但是不知道是項目中出現(xiàn)了問題,還是經(jīng)nginx代理后出現(xiàn)了問題。
因此要分別測試 項目本身的接口 和 nginx代理后的接口。
首先測試項目內(nèi)接口:
在ubuntu端輸入命令:curl http://localhost:port/xxx/xxx
這里我的接口是: curl http://localhost:20294/sys/login
運行結(jié)果:
說明我的項目內(nèi)接口是沒有問題的。
再測試nginx代理后的接口:
再ubuntu中輸入命令
curl http://localhost:8080/api/user/login
運行結(jié)果:
這里提示找不到接口了,說明問題出在代理服務(wù)器nginx上,所以我們要去修改nginx的配置文件。
按照其他博客的建議,我將nginx配置中這個地方加上了斜杠
重啟服務(wù)器后,還是不行。
徹底解決
在當(dāng)我不知道怎么辦的時候,我突然發(fā)現(xiàn)我的服務(wù)器中,有兩個nginx·····
我在想是不是因為有兩個nginx,修改的配置文件不是我啟動的那個nginx。于是我把所有nginx配置文件都替換成我原始的配置文件,再重啟。還是不行
擔(dān)心是兩個nginx的問題,我把服務(wù)器中的所有nginx刪除了。刪除步驟(依次運行下面的步驟):
ps aux|grep nginx #查看nginx進程 kill -9 進程號 #殺死上一步中查詢到的nginx(進程號在第二列) find / -name nginx #找到nginx的文件地址 rm -rf xxx #刪除nginx所有文件
最后用weget安裝新的nginx,然后按照原本安裝步驟進行安裝,修改配置文件后,再運行curl訪問動態(tài)接口,突然就可以了!
下面貼出我的nginx配置文件:
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; } } }
需要注意的是:配置動態(tài)訪問api的時候,記得在最后加上斜杠
至此,問題完美解決。
到此這篇關(guān)于nginx訪問動態(tài)接口報錯404Not Found問題解決的文章就介紹到這了,更多相關(guān)nginx訪問動態(tài)接口報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx服務(wù)器抵御CC攻擊的相關(guān)配置講解
這篇文章主要介紹了Nginx服務(wù)器抵御CC攻擊的相關(guān)配置講解,CC攻擊原理與DDoS基本相似而且技術(shù)含量低,注意防范即可,需要的朋友可以參考下2016-01-01Nginx服務(wù)器下配置個性二級域名及多個域名的實例講解
這篇文章主要介紹了Nginx服務(wù)器下配置個性二級域名及多個域名的實例講解,注意一下rewrite的寫法規(guī)則,需要的朋友可以參考下2016-01-01Centos7安裝、卸載nginx及配置,配置成系統(tǒng)服務(wù)方式(一步到位)
這篇文章主要介紹了Centos7安裝、卸載nginx及配置,配置成系統(tǒng)服務(wù)方式(一步到位),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12nginx提示:500 Internal Server Error錯誤的解決方法
本文章來給大家總結(jié)了大量關(guān)于導(dǎo)致nginx中提示500 Internal Server Error錯誤的原因總結(jié)與解決方法分析有需要了解的朋友可參考參考2013-04-04