Nginx docker容器版部署訪問403的解決
更新時間:2023年12月06日 08:56:38 作者:緣友一世
本文主要介紹了Nginx docker容器版部署訪問403的解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
問題記錄
- nginx.conf日志中出現(xiàn),403問題,由于容器版的nginx中沒有任何編輯工具,所以不太容器在容器中查看nginx文件的配置內(nèi)容
- 可能是權(quán)限問題,分析為主要是代理請求出現(xiàn)問題,沒有代理到正確的遠(yuǎn)程服務(wù)器。從日志中可以看到,代理后的請求并沒有發(fā)送到遠(yuǎn)程主機(jī)。
1.194.128.78 - - [04/Dec/2023:11:12:39 +0000] "GET /api/product/getBaseCategoryList HTTP/1.1" 403 238 "http://47.92.131.235/home" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36 Edg/119.0.0.0"
解決結(jié)果
- 經(jīng)過小編的瘋狂探索和嘗試,從本地nginx的初始配置文件經(jīng)過修改,最終,可以正常的配置文件內(nèi)容如下:
- 請根據(jù)自己的項(xiàng)目,基于本配置文件進(jìn)行修改,進(jìn)行嘗試
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; server { listen 80; server_name _; # include /etc/nginx/default.d/*.conf; location / { root #本地vue項(xiàng)目地址; try_files $uri $uri/ /index.html; index index.html; } location /api { proxy_pass 遠(yuǎn)程主機(jī)地址; #http://xxx.xxx.xxx.xxx } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } server { listen 8080; server_name localhost; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; location / { root #本地vue項(xiàng)目地址; try_files $uri $uri/ /index.html; index index.html index.htm; } # 監(jiān)聽的請求location 請根據(jù)時機(jī)項(xiàng)目內(nèi)容進(jìn)行配置 location /dev-api/ { proxy_pass 遠(yuǎn)程主機(jī)地址; #http://xxx.xxx.xxx.xxx proxy_set_header Host $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; rewrite ^/dev-api/(.*)$ /$1 break; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
到此這篇關(guān)于Nginx docker容器版部署訪問403的解決的文章就介紹到這了,更多相關(guān)Nginx docker部署訪問403內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何利用Docker容器實(shí)現(xiàn)代理轉(zhuǎn)發(fā)與數(shù)據(jù)備份詳解
這篇文章主要給大家介紹了關(guān)于如何利用Docker容器實(shí)現(xiàn)代理轉(zhuǎn)發(fā)與數(shù)據(jù)備份的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10關(guān)于docker部署fastapi項(xiàng)目以及日志掛載方式
這篇文章主要介紹了關(guān)于docker部署fastapi項(xiàng)目以及日志掛載方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03如何讓docker中的mysql啟動時自動執(zhí)行sql語句
這篇文章主要介紹了讓docker中的mysql啟動時自動執(zhí)行sql的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09使用腳本一鍵打包并上傳docker鏡像的實(shí)現(xiàn)代碼
這篇文章主要介紹了使用腳本一鍵打包并上傳docker鏡像的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02使用Maven和遠(yuǎn)程Docker基于Dockerfile構(gòu)建SpringBoot應(yīng)用鏡像
本文重點(diǎn)給大家介紹使用Maven和遠(yuǎn)程Docker基于Dockerfile構(gòu)建SpringBoot應(yīng)用鏡像的相關(guān)操作,感興趣的朋友跟隨小編一起看看吧2024-06-06