国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

請教一個 nginx 和 webman搭配使用的問題

banro512

比如 我的域名為 explame.com, nginx 里網(wǎng)站目錄指向 public,nginx中默認文檔已設(shè)為index.html

在public目錄下有個 index.html

我想在直接訪問 http://explame.com 時,能顯示靜態(tài)index.html里的內(nèi)容,而不必再經(jīng)由webman路由

upstream webman {
    server 127.0.0.1:8788;
}
server
{
    listen 80;
    server_name ********;
    index index.html;
    root /www/wwwroot/ybtask/public;
      location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Host $host;
          if (!-f $request_filename){
              proxy_pass http://webman;
          }
      }
}

這樣配置后,直接訪問域名是反代到了 webman,只有使用 http://explame.com/index.html 才能正確訪問到。
同理如果public下有個ucenter目錄,而該目錄下有個index.html,也是只有使用 http://explame.com/ucenter/index.html 才能訪問到這個index.html。如果省略了該index.html 就走到了webman。

嘗試過 try_files $uri @webman; 這樣配置,也是一樣。

目前狀態(tài):

訪問 http://explame.com/ucenter/index.html ,沒有反代到webman,正常顯示 index.html里內(nèi)容,沒問題

訪問 http://explame.com/api/getmyinfo ,正常反代到了 webman,也沒問題

但如果 省略掉 index.html 去訪問 http://explame.com/ucenter 那么就被反代到了 webman,雖然本意只是想顯示 ucenter/index.html 這個文件

目的是想在訪問 http://explame.com/ucenter 這類地址時,先讓nginx判斷下是否存 http://explame.com/ucenter/index.html 文件,如果存在,那么就直接顯示這個文件,如果不存在,再反代到webman。

2396 3 3
3個回答

oscar

網(wǎng)站不應(yīng)該指向public目錄吧
應(yīng)該是只配置靜態(tài)文件走public就可以了。

  • banro512 2022-04-21

    不指向public,那應(yīng)該如何指向?

    指向應(yīng)該沒問題,現(xiàn)在的問題是:訪問某個目錄下的靜態(tài) index.html時,無法省略index.html,雖然已在nginx里將默認文檔設(shè)為了index.html

    比如訪問 http://explame.com/ucenter/index.html ,一切正常,沒有反代到webman
    比如訪問 http://explame.com/api/getmyinfo ,正常反代到 webman,也沒問題

    但如果 省略掉 index.html 去訪問 http://explame.com/ucenter 那么就被反代到了 webman,雖然本意是想顯示 ucenter/index.html 這個文件

  • banro512 2022-04-21

    其實就是說:在訪問 http://explame.com/api/getmyinfo 時,想先讓nginx判斷下是否存 http://explame.com/api/getmyinfo/index.html 文件,如果存在,那么直接顯示這個文件,如果不存在,再反代到webman,就是這個效果

  • oscar 2022-04-21

    不應(yīng)該是這樣,只有public目錄下的文件才能被外部訪問,除此之外,所有的url都是走路由?

  • banro512 2022-04-21

    你說的沒錯,但你沒明白我的意思,我是想訪問public中某個目錄下的index.html文件時,能實現(xiàn)省略index.html的目錄。
    比如 public/abc/index.html 我是想 域名/abc 能實現(xiàn)和 域名/abc/index.html 一樣的效果

six

nginx 配置里加一句
index index.html;
比如

server {
        listen 80;
        server_name  myadmin.com;
        root /www/wwwroot/webman/public;
        index index.html ;

        .....

}
  • banro512 2022-04-21

    已經(jīng)加了的
    如果去掉反代配置,沒問題,是我想要的效果,但加上那個反代到webman配置后,就必須加index.html

  • shixia 2022-04-21

    我懂你的意思 就是靜態(tài)文件nginx處理 ,動態(tài)請求轉(zhuǎn)發(fā)webman 對吧

  • shixia 2022-04-21

    你可以看一下這一篇文章

  • shixia 2022-04-21

    里面講的很詳細我寫的

  • shixia 2022-04-21

    你設(shè)置非靜態(tài)文件轉(zhuǎn)發(fā)就可以了

  • banro512 2022-04-21

    不是。
    那個能設(shè)置,是要實現(xiàn)nginx的默認文檔功能,比如nginx里默認文檔 index.html。
    訪問 /ucenter 時,先判斷是否存在 /ucenter/index.html 這個文件,存在時就直接顯示,不存在的話再反代。
    目前是訪問 /ucenter 時,直接就反代到了 webman,雖然存在 /ucenter/index.html
    我知道直接 /ucenter/index.html 是可以的,只是有需求,想在url中省略 這個index.html

北月妖王
location / {
  error_page 405 = @webman;
  try_files /${uri}/index.html /${uri} /${uri}/index.html @webman;
}
## WEBMAN LOCATION
location @webman {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8787;
}
  • oscar 2022-04-21

    剛測試了,沒問題的。只要目錄里有index.html同時配置了index index.html,訪問時加不加index.html都是先訪問到index.html 。我是這么做的,假設(shè)靜態(tài)目錄的訪問路徑為abc.com/public/,我就只配置了
    location /public/ {
    root /yourSitePath/;
    }

  • 北月妖王 2022-04-21

    你說的對,如果有固定前綴就很好配置了

  • banro512 2022-04-21

    按照這樣配置可以了。3q

    =====

    不想在訪問時有public前綴。

    其實這個就是想實現(xiàn)在 nginx+php-fpm時一樣的效果:public下是靜態(tài)文件,nginx里網(wǎng)站根目錄指向public(訪問時url不帶有public)
    public下有很多目錄和html文件,各個目錄下也有html文件,比如 index.html, ucenter,admin,doc,css,js等,在訪問時,如果指向的是這些目錄(如 /ucenter , /admin ),那么就直接顯示這些目錄下的 index.html。

    在單純nginx+php-fpm時,這些默認都是可以的,只是加了反代配置后,如果url沒有精確匹配到 index.html 文件,就被反代了。
    一直沒搞明白怎么配置。

    現(xiàn)在明白了,多謝 各位的回答

  • oscar 2022-04-21

    如果要那樣在webman里應(yīng)該是不行的,你那種想法其實就是fpm所有框架的單入口,路徑逐個解析。但是在webman里默認就限制只有public目錄可以被瀏覽器訪問,雖然public也可以改名,意義不大。如果你有多個前綴,那就多配置幾條規(guī)則就可以了。也不一定要是以public開頭,只要root指向到webman里的public目錄就可以了。比如/ucenter/=>/public/ucenter,/admin=>/public/admin,如此如此

  • banro512 2022-04-21

    明白了,3q。

年代過于久遠,無法發(fā)表回答
??