欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nginx的location配置導(dǎo)致網(wǎng)關(guān)返回404問題

 更新時(shí)間:2024年06月20日 08:49:10   作者:飄零未歸人  
這篇文章主要介紹了nginx的location配置導(dǎo)致網(wǎng)關(guān)返回404問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

nginx的location配置導(dǎo)致網(wǎng)關(guān)返回404

再項(xiàng)目中使用nginx轉(zhuǎn)發(fā)到網(wǎng)關(guān)時(shí),發(fā)現(xiàn)返回了404.

{

    "timestamp": "2023-11-01T02:12:48.788+00:00",

    "path": "http://core-manage-web/core/core-manage/servers/findServers",

    "status": 404,

    "error": "Not Found",

    "message": null,

    "requestId": "642b125b"

}

從這個(gè)返回來看,應(yīng)該是網(wǎng)關(guān)返回的信息。因?yàn)槿绻莕ginx返回404的話,應(yīng)該是返回的404.html才對。

所以看看出是網(wǎng)關(guān)找不到轉(zhuǎn)發(fā)的路徑。 從  "path": "//core-manage-web/core/core-manage/servers/findServers",看出我們的接口經(jīng)過nginx轉(zhuǎn)發(fā)之后,居然只有兩個(gè)//。正常應(yīng)該只有一個(gè)才對。

再看一下location配置:

location /core {
    proxy_pass http://gateway-upstream/;
}

由于第一次使用使用nginx,所以對于這些配置還不是很了解。這上面的的  “location /core”標(biāo)識路徑前綴匹配。 而我的 “http://core-gateway-upstream/”是以“/”結(jié)尾,這表示會(huì)將 location的匹配路徑(/core)替換掉在轉(zhuǎn)發(fā)。

gateway-upstream配置如下

upstream gateway-upstream {
    server 192.168.111.1:10006;
}

所以如果我是用 http:localhost:8080/core/login/xxxxx訪問,則經(jīng)過nginx轉(zhuǎn)發(fā)之后會(huì)變成192.168.111.1:10006//login/xxxxx

所以需要將 location /core改成 location /core/。即可:

location /core/ {
    proxy_pass http://gateway-upstream/;
}

nginx配置多個(gè)location訪問報(bào)404

解決方法

在自己配置的location中不要使用root配置文件目錄,替換為alias即可

完整配置

#user  nobody;
worker_processes  1;

#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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            autoindex on;             #開啟索引功能
            autoindex_exact_size off; # 關(guān)閉計(jì)算文件確切大小(單位bytes),只顯示大概大小(單位kb、mb、gb)
            autoindex_localtime on;   # 顯示本機(jī)時(shí)間而非 GMT 時(shí)間
            charset utf-8; # 避免中文亂碼
            root   file;
            #index  index.html index.htm;
        }
        
        location /file {
	    alias   html;
            index  index.html index.htm;
	}
        #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;
        #    include        fastcgi_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;
    #    }
    #}

}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • nginx提示:500 Internal Server Error錯(cuò)誤的解決方法

    nginx提示:500 Internal Server Error錯(cuò)誤的解決方法

    本文章來給大家總結(jié)了大量關(guān)于導(dǎo)致nginx中提示500 Internal Server Error錯(cuò)誤的原因總結(jié)與解決方法分析有需要了解的朋友可參考參考
    2013-04-04
  • 基于nginx反向代理獲取用戶真實(shí)Ip地址詳解

    基于nginx反向代理獲取用戶真實(shí)Ip地址詳解

    我們訪問互聯(lián)網(wǎng)上的服務(wù)時(shí),大多數(shù)時(shí)客戶端并不是直接訪問到服務(wù)端的,而是客戶端首先請求到反向代理,反向代理再轉(zhuǎn)發(fā)到服務(wù)端實(shí)現(xiàn)服務(wù)訪問,這篇文章主要給大家介紹了關(guān)于如何基于nginx反向代理獲取用戶真實(shí)Ip地址的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • 使用nginx部署前端項(xiàng)目的實(shí)現(xiàn)

    使用nginx部署前端項(xiàng)目的實(shí)現(xiàn)

    前端項(xiàng)目的部署以前一直是把靜態(tài)資源放到后端工程中,隨后端部署一起部署,本文主要介紹了使用nginx部署前端項(xiàng)目的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • 配置ab來為Nginx服務(wù)器做壓力測試的方法

    配置ab來為Nginx服務(wù)器做壓力測試的方法

    這篇文章主要介紹了配置ab來為Nginx服務(wù)器做壓力測試的方法,ab是針對Apache的測試工具但本文講解其測試Nginx的過程,需要的朋友可以參考下
    2016-01-01
  • 隱藏網(wǎng)站Nginx版本號信息的方法分享

    隱藏網(wǎng)站Nginx版本號信息的方法分享

    隱藏網(wǎng)站nginx服務(wù)的版本號信息,在安全的角度上來說,可以防止黑客快速利用nginx的版本漏洞進(jìn)行攻擊,所以本文為大家整理了隱藏網(wǎng)站Nginx版本號信息的方法,希望對大家有所幫助
    2023-08-08
  • Nginx下配置pathinfo及ThinkPHP的URL Rewrite模式支持

    Nginx下配置pathinfo及ThinkPHP的URL Rewrite模式支持

    這篇文章主要介紹了Nginx下配置pathinfo及ThinkPHP的URL Rewrite模式支持,使用Nginx運(yùn)行ThinkPHP的必備配置,需要的朋友可以參考下
    2015-07-07
  • nginx前綴匹配的實(shí)現(xiàn)

    nginx前綴匹配的實(shí)現(xiàn)

    在nginx的配置文件中,很容易的看到location的模塊,本文主要介紹了nginx前綴匹配的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-04-04
  • Nginx 防止目錄遍歷的方法實(shí)現(xiàn)

    Nginx 防止目錄遍歷的方法實(shí)現(xiàn)

    目錄遍歷攻擊是一種常見的Web安全漏洞,本文主要介紹了Nginx防止目錄遍歷的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-12-12
  • 使用nginx如何實(shí)現(xiàn)請求轉(zhuǎn)發(fā)的功能

    使用nginx如何實(shí)現(xiàn)請求轉(zhuǎn)發(fā)的功能

    文章介紹了如何配置Nginx作為反向代理服務(wù)器,實(shí)現(xiàn)請求轉(zhuǎn)發(fā)和負(fù)載均衡,并進(jìn)行了靜態(tài)和動(dòng)態(tài)內(nèi)容分離,主要步驟包括修改Nginx默認(rèn)端口、配置轉(zhuǎn)發(fā)規(guī)則和修改配置文件
    2024-12-12
  • 詳解Nginx如何代理UDP連接

    詳解Nginx如何代理UDP連接

    這篇文章主要為大家介紹了Nginx如何代理UDP連接的實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06

最新評論