国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

前端部署項目后nginx轉發(fā)接口404(頁面正常)詳解

瀏覽:12日期:2023-08-03 20:13:38
目錄1.前言 2. 場景復現(xiàn):3.問題的原因:4.使用nginx一般要注意的小細節(jié): 5.使用nginx常用的命令:6.常用nginx配置文件(可以參考,根據(jù)自己實際項目修改一下即可)總結1.前言

本來很簡單的一個事,結果老是報錯,郁悶的睡不著,于是半夜起床擼起袖子干……

最后功夫不負有心人,終于找到解決方法并且成功了。

2. 場景復現(xiàn):

前端部分是用的vue3,本地代理什么的一切正常,然后前端打包生成dist文件,然后放到服務器上(你要記得存放的路徑),現(xiàn)在都是前后端分離開發(fā),之前我部署都是前后端在一個服務器上,這次后端部署在A服務器,我部署在B服務器。

本來按照正常思路都是修改nginx的conf文件,然后加一個location /api之類的就夠了,但是這次卻出問題了。

3.問題的原因:

這次問題的核心是:

之前我是這么寫的(錯誤)

location ^~ /v1 {proxy_pass https://XXXXX.neimeng.seetacloud.com:6443/api/; }

后來我是這么寫的(正確)

location /v1 { proxy_pass https://XXXXXXeimeng.seetacloud.com:6443/api/v1;}

其實區(qū)別就是最后加了一個/v1

也是今天出的最大問題:那就是—— /v1 在轉發(fā)的時候不會帶上/v1; 而 /v1/ 這么寫會帶上/v1

4.使用nginx一般要注意的小細節(jié):

1. location / 寫在下面,其他的轉發(fā)如/v1寫在上面

2.如何查看nginx轉發(fā)請求到哪里了?

在serve里面, location / {} 上面粘貼即可

add_header backendCode $upstream_status; add_header BackendIP '$upstream_addr;' always;

3.怎么寫自己的前端路徑?

在location里面 root 的右邊寫(格式參考C語言),上圖紅色框標識了。

5.使用nginx常用的命令:

1. 查看所有運行中的nginx進程

tasklist | findstr nginx

2.刪除某個運行中的進程

taskkill /pid 3584(具體的進程pid可以根據(jù)上面的命令自己看) /f

3.檢查conf配置文件是否有錯誤

nginx - t

4.重啟nginx

nginx -s reload 6.常用nginx配置文件(可以參考,根據(jù)自己實際項目修改一下即可)#user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info; #pidlogs/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''; #access_log logs/access.log main; sendfileon; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server {listen 80;server_name 你的服務器IP; #charset koi8-r; #access_log logs/host.access.log main; add_header backendCode $upstream_status;add_header BackendIP '$upstream_addr;' always; location /v1 { proxy_pass https://后端地址;}location / { root C:/Users/你的前端文件存放目錄; index index.html index.htm;try_files $uri $uri/ /index.html;} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html { root html;} # proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# includefastcgi_params;#} # deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { #root html; #index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { #root html; #index index.html index.htm; # } #}}總結

到此這篇關于前端部署項目后nginx轉發(fā)接口404(頁面正常)的文章就介紹到這了,更多相關前端nginx轉發(fā)接口404內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Nginx
主站蜘蛛池模板: 伊人久久青草青青综合 | 免费一级性片 | 国产亚洲精品一区久久 | 成人午夜影院 | 最新国产三级在线不卡视频 | 三级理论手机在线观看视频 | 大量愉拍情侣在线视频 | 国产成人在线网址 | 国产亚洲精品资源一区 | 91热国内精品永久免费观看 | 在线免费观看一级毛片 | 欧美一级毛片兔费播放 | 亚洲伊人色综合网站亚洲伊人 | 免费黄色在线网址 | 亚洲午夜免费 | 日本亚洲欧美高清专区vr专区 | 波多野结衣被强在线视频 | 亚洲成人播放 | 成人免费在线视频网 | 亚州一二区 | 在线观看国产精成人品 | 亚洲天堂免费观看 | 亚洲国产精品乱码在线观看97 | chinese多姿势videos | 九九在线免费视频 | 亚洲国产日韩在线 | 美国一级毛片完整高清 | 免费刺激视频 | 91成人在线免费观看 | 国产精品欧美一区二区 | 自拍视频网 | 韩日三级视频 | 黄网站免费在线 | 国产成人精品高清不卡在线 | 真正免费一级毛片在线播放 | 国产欧美日韩精品一区二 | 99精品国产在现线免费 | 美国特级毛片 | 国产精品自在自线亚洲 | 久久香蕉国产观看猫咪3atv | 日本特黄特色高清免费视频 |