「/」のnginxの終わりに

まず、のtomcatの127.0.0.1:8081内の構成ファイル:

、ROOT / a.html 1:これは、ROOTのページです

2、ROOT / testa.html:nihao

、ROOT / index.htmlを3:これは、ROOTのインデックスページです

4、テスト/ a.html   :  これはテストページです

5、テスト/ index.htmlを  :  これはテスト・インデックス・ページです

 

二、nginxのserver_nameは、以下のように構成されました:

。1 、proxy_pass URIをパスすることなく:

サーバー{

        80を聞きます。

        サーバー名www.test.com;

        位置/ nihao {            

            proxy_pass http://127.0.0.1:8081。

            インデックス  のindex.html;

        } 

                #location なし/ポスト  proxy_passなし/後  http://127.0.0.1:8081にエージェント/nihao/a.html

                #curl http://www.test.com/nihao/a.html     ハローディレクトリが存在しないため、

             #ご要請のリソースはご利用できません

 

        位置/テスト{

            proxy_pass http://127.0.0.1:8081。

            インデックス  のindex.html;

        }

                #location なし/ポスト  proxy_passなし/後  http://127.0.0.1:8081にエージェント/test/a.html

              #curl http://www.test.com/test/a.html

              #このテストページです

 

        位置/ハロー/ {

            proxy_pass http://127.0.0.1:8081。

            インデックス  のindex.html;

        }

                #location 後に/と  なし/後proxy_pass   http://127.0.0.1:8081にエージェント/hello/a.html

                #curl http://www.test.com/hello/     ハローディレクトリが存在しないため、

             #ご要請のリソースはご利用できません

        位置/試験/ {

            proxy_pass http://127.0.0.1:8081。

            インデックス  のindex.html;

        }

               #location 後に/と  なし/後proxy_pass   http://127.0.0.1:8081にエージェント/test/a.html

               #curl http://www.test.com/test/

            #このテスト・インデックス・ページです

}

サーバー{

        80を聞きます。

        SERVER_NAME www.test1.com;

        位置/ nihao {

            proxy_pass http://127.0.0.1:8081/。

            インデックス  のindex.html;

        }

              #locationのなし/ポスト  proxy_passは/持って後  http://127.0.0.1:8081にエージェントを/a.html

              #curl http://www.test1.com/nihao/a.html

            #このROOTページです

 

        位置/テスト{

            proxy_pass http://127.0.0.1:8081/。

            インデックス  のindex.html;

        }

            #locationのなし/ポスト  proxy_passは/持って後  http://127.0.0.1:8081にエージェントを/a.html   

             #curl http://www.test1.com/test/a.html

           #このROOTページです

 

        位置/ハロー/ {

            proxy_pass http://127.0.0.1:8081/。

            インデックス  のindex.html;

        }

            #location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/index.html

            #curl http://www.test1.com/hello/

          #this is ROOT index page

 

        location /test/ {

            proxy_pass http://127.0.0.1:8081/;

            index  index.html;

        }

            #location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/index.html

           #curl http://www.test1.com/test/

         #this is ROOT index page

}

 

2、proxy_pass的URI带路径:

server {

        listen 80;

        server_name www.test.com;

        location /nihao {

            proxy_pass http://127.0.0.1:8081/test;

            index  index.html;

        }

                #location 后无/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/test/a.html

             #curl http://www.test.com/nihao/a.html

             #this is test page

             #curl http://www.test.com/nihao

             #this is test index page

 

        location /test {

            proxy_pass http://127.0.0.1:8081/test;

            index  index.html;

        }

               #location 后无/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/test//

             #curl http://www.test.com/test  重定向为:http://www.test.com/test//

             #指向此网址的请求无限循环重定向

 

        location /hello/ {

            proxy_pass http://127.0.0.1:8081/test;

            index  index.html;

        }

               #location 后有/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/testa.html

             #curl http://www.test.com/hello/a.html

             #nihao

             #curl http://www.test.com/hello/   重定向为:http://www.test.com/hello//

             #指向此网址的请求无限循环重定向

 

        location /test/ {

            proxy_pass http://127.0.0.1:8081/test;

            index  index.html;

        }

               #location 后有/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/testa.html

             #curl http://www.test.com/test/a.html

             #nihao

             #curl http://www.test.com/test/  重定向为:http://www.test.com/test//

             #指向此网址的请求无限循环重定向

}

server {

        listen 80;

        server_name www.test1.com;

        location /nihao {

            proxy_pass http://127.0.0.1:8081/test/;

            index  index.html;

        }

               #location 后无/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/a.html

             #curl http://www.test1.com/nihao

             #this is test index page

             #curl http://www.test1.com/nihao/a.html

             #this is test page

 

        location /test {

            proxy_pass http://127.0.0.1:8081/test/;

            index  index.html;

        }

               #location 后无/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/index.html

             #curl http://www.test1.com/test

             #this is test index page

 

        location /hello/ {

            proxy_pass http://127.0.0.1:8081/test/;

            index  index.html;

        }

               #location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/a.html

             #curl http://www.test1.com/hello

             #this is test index page

             #curl http://www.test1.com/hello/a.html

             #this is test page

        location /test/ {

            proxy_pass http://127.0.0.1:8081/test/;

            index  index.html;

        }

                #location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/a.html

              #curl http://www.test1.com/test/a.html

              #this is test page

}

 

三、总结:

nginx中配置proxy_pass代理转发时,如果在proxy_pass后面的url/,表示绝对根路径;如果没有/,表示相对路径,把匹配的路径部分也给代理走。

proxy_pass的URI带路径中如果location的不带/,最好proxy_pass也不带;

おすすめ

転載: www.cnblogs.com/wushank/p/11730557.html