2017-09-08 1 views
0

私は現在、URLパスを使用するJSプロジェクトに取り組んでいます。私は実際にexample.com/index.htmlを必要とするので、今、私はexample.com/で私のウェブサイトに行けば、JavaScriptは、動作しません。プロキシパスを/ to /index.htmlに転送する方法

私はすでに、2つの異なるドッカーコンテナへのプロキシパスにリバースプロキシを使用しています。ですから、私の考えは、example.com/index.htmlexample.com/と呼ばれるときに要求を渡すことでした。しかし、私はこの目標を達成するために正規表現のものを理解することはできません。

私の古い設定:

server { 
listen  80; 
server_name example.com; 

# allow large uploads of files - refer to nginx documentation 
client_max_body_size 1G; 

# optimize downloading files larger than 1G - refer to nginx doc 
before adjusting 
#proxy_max_temp_file_size 2G; 

location/{ 
    proxy_pass http://structure.example:80; 
} 

location /cdn { 
    proxy_pass http://content.example:80; 
} 

error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root /usr/share/nginx/html; 
} 

} 

スタッフ、私が試した:コンフィグ以下

server { 
listen  80; 
server_name example.com; 

# allow large uploads of files - refer to nginx documentation 
client_max_body_size 1G; 

# optimize downloading files larger than 1G - refer to nginx doc 
before adjusting 
#proxy_max_temp_file_size 2G; 

location/{ 
    proxy_pass http://structure.nocms:80/index.html; 
} 

location ~* \S+ { 
    proxy_pass http://structure.nocms:80; 
} 

location /cdn { 
    proxy_pass http://content.nocms:80; 
} 



error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root /usr/share/nginx/html; 
} 

} 
+0

を動作するはずです '最後/index.htmlが^/$書き換え追加してみてください; 'あなたのサーバブロック内 –

+0

@ TarunLalwani残念なことに、Dosenの仕事はありません。しかし、とにかくありがとうございます –

+0

index.htmlは、 '/ usr/share/nginx/html'ディスクから提供される必要があり、他のURLに渡されるプロキシではありませんか? –

答えて

1

はあなたのために

server { 
listen  80; 
server_name example.com; 

# allow large uploads of files - refer to nginx documentation 
client_max_body_size 1G; 

# optimize downloading files larger than 1G - refer to nginx doc 
before adjusting 
#proxy_max_temp_file_size 2G; 

location =/{ 
    rewrite^/index.html permanent; 
} 

location/{ 
    proxy_pass http://structure.example:80; 
} 

location /cdn { 
    proxy_pass http://content.example:80; 
} 

error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root /usr/share/nginx/html; 
} 

} 
+0

私はすでに自分自身、don't作業.... –

+0

あなたはまた、index.htmlから来るように変更するだけでブラウザのURLが必要ですか? –

+0

技術的にはURLだけが必要です。私はjsで 'window.location.pathname'を使います。 –

関連する問題