国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

nginx設(shè)置重定向跳轉(zhuǎn)后ip:[端口]/abc變成ip/abc而報錯404

這篇具有很好參考價值的文章主要介紹了nginx設(shè)置重定向跳轉(zhuǎn)后ip:[端口]/abc變成ip/abc而報錯404。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

nginx設(shè)置重定向跳轉(zhuǎn)后??ip:[端口]/abc??變成??ip/abc??而報錯404

nginx配置:

    server {
        listen    80;
        server_name  _;
        client_max_body_size 300m;
        absolute_redirect off;


        location / {
            root     html;
            index  index.html index.htm;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }

    ## abc目錄
        location /abc/ {
        if (-d $request_filename) {
           rewrite [^/]$ $scheme://$http_host$uri/ permanent;
        }
            proxy_pass http://localhost:8088/;?
? ? ? ? ? ? ##由于規(guī)定了流量出口必須是80,所以得在80的server上代理出8088端口的abc項目
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_http_version 1.1;
        proxy_read_timeout   3600s;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
            add_header X-Cache $upstream_cache_status;
        add_header Cache-Control no-cache;

        }

 

server {
        listen       8088;
        server_name  _;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        charset utf-8;
        location / {
            root /opt/abc/;
       ???? index  index.html index.htm;
            autoindex_exact_size off;
            autoindex_localtime on;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host:$server_port;

        }
        }

本地測試項目是否能正常訪問:

http://192.168.1.22:8088?正常訪問

http://192.168.1.22/abc?正常訪問

當(dāng)我需要將192.168.1.22:8088映射到外網(wǎng)ip:[port]?進行外網(wǎng)訪問時報錯。

假設(shè)外網(wǎng)ip=122.23.43.21

路由分配:122.23.43.21:5566??指向內(nèi)網(wǎng)??-->?192.168.1.22:8088

也就是說,當(dāng)我訪問?122.23.43.21:5566/abc?時?可訪問http://192.168.1.22:8088 項目

但是當(dāng)我使用外網(wǎng)地址訪問項目時:

http://122.23.43.21:5566/abc/????項目正常訪問

http://122.23.43.21:5566/abc 項目由?

http://122.23.43.21:5566/abc ??重定向為?http://122.23.43.21/abc/ ??而導(dǎo)致報錯404

也就是說在nginx.conf里,nginx把所有的ip:[port]都會自動跳轉(zhuǎn)成ip:80?也就是默認(rèn)重定向后是80端口,而外網(wǎng)ip的80端口是沒有作映射的,所以404

此時我們需要知道,重定向錯誤,必定出在nginx上。所以需要從server里下手

在反向代理中添加?absolute_redirect off;?

 server {
        listen       8088;
        server_name  _;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        charset utf-8;
        location / {
            root /home/web/zhuhai-forest-resources-management/;
        index  index.html index.htm;
            autoindex off; ##防止ip:[port]/test 重定向請求后變成 ip/test而導(dǎo)致404
            autoindex_exact_size off;
            autoindex_localtime on;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host:$server_port;

        }
        }

即可成功訪問

參考如下文章:

nginx重定向?qū)е露丝谙o法正常訪問

場景

訪問路徑帶端口http://ip:端口/login,回車后端口消失http://ip/login無法正常訪問

解決方法

nginx配置中中加一句:

新版本nginx(≥1.11.8)

absolute_redirect off;

舊版本nginx(<1.11.8)

port_in_redirect off;
nginx設(shè)置重定向跳轉(zhuǎn)后ip:[端口]/abc變成ip/abc而報錯404

番外:

1. 關(guān)于nginx自動跳轉(zhuǎn)

站點目錄結(jié)構(gòu):

根目錄:/var/wwwroot/test/

nginx設(shè)置重定向跳轉(zhuǎn)后ip:[端口]/abc變成ip/abc而報錯404

當(dāng)訪問地址為 http://www.test.com/abc 時,因為nginx未找到abc這個文件,而是找到了abc目錄,自動在地址后面加上了斜杠,所以自動發(fā)生 301 跳轉(zhuǎn)到 http://www.test.com/abc/

2. nginx自動跳轉(zhuǎn)相關(guān)的3個配置

Nginx中存在一三個跳轉(zhuǎn)的相關(guān)配置:

1. absolute_redirect

Syntax:	absolute_redirect on | off;Default:	absolute_redirect on;Context:	http, server, locationThis directive appeared in version 1.11.8.If disabled, redirects issued by nginx will be relative.See also server_name_in_redirect and port_in_redirect directives.

默認(rèn)為開啟。

2. server_name_in_redirect

Syntax:	server_name_in_redirect on | off;Default:	server_name_in_redirect off;Context:	http, server, locationEnables or disables the useof the primary server name, specified by the server_name directive, in absolute redirects issued by nginx. When the useof the primary server name is disabled, the name from the “Host” request header field is used. If this field isnotpresent, the IP addressof the server is used.The use of a port in redirects is controlled by the port_in_redirect directive.

默認(rèn)關(guān)閉

3. port_in_redirect

Syntax:	port_in_redirect on | off;Default:	port_in_redirect on;Context:	http, server, locationEnables or disables specifying the port in absolute redirects issued by nginx.The use of the primary server name in redirects is controlled by the server_name_in_redirect directive.

默認(rèn)開啟。

3. 舉例

訪問地址為:http://192.168.1.232/abc

Nginx情況一:

server {    listen 80;    server_name test.com;    absolute_redirect off; // 關(guān)閉了它,不管 server_name_in_redirect, port_in_redirect 怎么設(shè)置都沒有用    server_name_in_redirect on;    port_in_redirect on;}

發(fā)生 301 跳轉(zhuǎn),跳轉(zhuǎn)后的地址為:http://192.168.1.232/abc/

官方說是使用 請求頭中的 Host 字段,作為url跳轉(zhuǎn)后host部分

nginx設(shè)置重定向跳轉(zhuǎn)后ip:[端口]/abc變成ip/abc而報錯404

Nginx情況二:

server {    listen 80;    server_name test.com;    absolute_redirect on; // 默認(rèn)為on, Nginx配置中沒有這個字段其實值是on, server_name_in_redirect, port_in_redirect 會根據(jù)配置起作用    server_name_in_redirect on; // 發(fā)生跳轉(zhuǎn)時使用 server 中配置的域名    port_in_redirect on; // 發(fā)生跳轉(zhuǎn)時使用 server 中配置的端口}

發(fā)生 301 跳轉(zhuǎn),跳轉(zhuǎn)后的地址為:http://test.com/abc/文章來源地址http://www.zghlxwxcb.cn/news/detail-474148.html

到了這里,關(guān)于nginx設(shè)置重定向跳轉(zhuǎn)后ip:[端口]/abc變成ip/abc而報錯404的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • nginx :80跳轉(zhuǎn)其他端口

    以docker nginx為例 修改docker-env.yml文件增加端口映射 修改nginx配置文件,增加server nginx -t? #測試配置文件是否通過 重新build和重啟nginx 服務(wù) 測試 http://xxx.xxx.com 是否跳轉(zhuǎn)到對應(yīng)的端口(如8001)

    2024年02月14日
    瀏覽(19)
  • vue路由跳轉(zhuǎn)后,刷新指定頁面。

    vue路由跳轉(zhuǎn)后,刷新指定頁面。

    ????????做項目遇到一個坑:A頁面帶參跳轉(zhuǎn)到B頁面,第二次跳轉(zhuǎn)時的參數(shù)與第一次時的參數(shù)不同,但是后臺查詢時還是使用的第一次的參數(shù)。需要手動刷新之后,才會使用第二次參數(shù)。 ? ? ? ? 鑒于時間原因直接使用刷新頁面監(jiān)聽路由的方法。在準(zhǔn)備跳轉(zhuǎn)的A頁面添加路

    2024年02月12日
    瀏覽(34)
  • 實戰(zhàn)指南:使用 Nginx 反向代理實現(xiàn)多端口跳轉(zhuǎn)

    實戰(zhàn)指南:使用 Nginx 反向代理實現(xiàn)多端口跳轉(zhuǎn)

    在現(xiàn)代 Web 開發(fā)中,Nginx作為一款高性能的開源反向代理服務(wù)器,提供了強大的功能來管理網(wǎng)絡(luò)流量和路由。本文將介紹如何利用 Nginx 的反向代理功能,將不同路徑的請求轉(zhuǎn)發(fā)到不同端口的 Tomcat 服務(wù)上,以實現(xiàn)多端口跳轉(zhuǎn)的效果。 使用 Nginx 的強大反向代理功能,我們能夠根

    2024年02月19日
    瀏覽(20)
  • 微信小程序優(yōu)化多次跳轉(zhuǎn)后卡頓問題

    一、微信小程序多次跳轉(zhuǎn)會產(chǎn)生卡頓的原理 通過wx.navigateTo 跳轉(zhuǎn),都會出現(xiàn)保留當(dāng)前頁面,打開新的頁面機制。 wx.navigateTo不會將舊頁面出棧,會將新頁面入棧(棧內(nèi)元素個數(shù)增加,棧內(nèi)元素5個時,不能再跳轉(zhuǎn))。手機性能好點,可能10次左右才會導(dǎo)致小程序跳轉(zhuǎn)卡頓崩潰。 二

    2024年02月11日
    瀏覽(57)
  • Nginx配置HTTPS跳轉(zhuǎn)到非443端口的技巧和注意事項

    近一段時間由于看到v*云服務(wù)廠商有活動,就注冊并開了臺云服務(wù)器,試一下區(qū)別。 (“充10美元送30天內(nèi)有效的250美元的免費額度,意思是30天內(nèi)在 你加起來 不超出250美元的 服務(wù)隨便開,但是注意的是30天后這就不免費了,記得及時關(guān)閉。只支持paypal,而阿里alipay一般是充值

    2023年04月18日
    瀏覽(20)
  • vue單頁面實現(xiàn)路由跳轉(zhuǎn)后保留原頁面數(shù)據(jù)

    有時候在路由跳轉(zhuǎn)后,返回原頁面時需要保留之前的數(shù)據(jù),即不銷毀頁面。 頁面的緩存,需要用到vue的內(nèi)置組件keep-alive,來緩存列表頁面,同時配合路由選項來更改頁面的數(shù)據(jù)。 在設(shè)置keep-alive緩存的組件中,首次進入組件,會一次調(diào)用組件的鉤子函數(shù):created -- mounted --ac

    2024年02月15日
    瀏覽(22)
  • 關(guān)于vue路由跳轉(zhuǎn)后的頁面不會刷新的解決辦法

    做uni項目的時候遇到的情況:1,父組件頁面刷新了之后 需要觸底加載的子組件能觸底加載,否則不能加載。2,子組件不能觸底加載,只需要刷新之后就能觸底加載。以上的刷新不包括下拉刷新。3. 可能因為包了一層tab頁導(dǎo)致跳轉(zhuǎn)進頁面沒有請求數(shù)據(jù)的問題。 我的解決辦法是

    2024年02月11日
    瀏覽(28)
  • nginx 映射ip端口服務(wù)

    nginx 映射ip端口服務(wù)

    筆者只對外開放了一個ip端口,但實際使用不止一個端口,那么需要把ip端口映射出來。這里使用Nginx來映射ip端口。比如將前端系統(tǒng)的ip端口映射出去了,還需要后臺的ip端口,這樣前后端才能結(jié)合使用 通過后臺服務(wù)名(dwiot-cloud)來分發(fā)到后臺服務(wù)ip端口,這樣可以直接通過

    2024年02月11日
    瀏覽(15)
  • Selenium頁面跳轉(zhuǎn)后的元素定位-switch_to.window()使用

    在使用Selenium獲取網(wǎng)頁數(shù)據(jù)時常常會因為頁面跳轉(zhuǎn)導(dǎo)致,后續(xù)的頁面數(shù)據(jù)無法正常獲取。究極原因,都是因為此時的頁面對象還是上一個頁面,使用當(dāng)前頁面的定位條件當(dāng)然會報錯(因為上一個頁面根本不存在這些定位條件)。因此我們可以通過switch_to.window()進行頁面的切換

    2023年04月09日
    瀏覽(20)
  • nginx安裝及(域名、端口、ip)配置

    nginx安裝及(域名、端口、ip)配置

    1、首先安裝pcre庫 說明:pcre使nginx具備URL重寫的rewrite模塊 1)查看系統(tǒng)環(huán)境 cat /etc/redhat-release 2)顯示64位系統(tǒng) uname -r? 、 uname -m ?2、yum安裝pcre命令 配置下載源 (1)安裝:yum install -y pcre pcre-devel 安裝后查看:rpm -qa pcre pcre-devel 注意:nginx安裝依賴pcre、pcre-devel 、openssl、open

    2024年02月05日
    瀏覽(15)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包