2016-10-11 15 views
0

http://example.comhttp://example.com/home.html /home/ubuntu/mysitedir/home.htmlから配信しようとしています。nginxのルートディレクティブが原因で404

私はすべてをhttpsに、そしてプロキシをuwsgiに正常にリダイレクトする次のconfファイルを持っています。 http-> httpsリダイレクトはうまく動作し、uwsgiプロキシは動作しますが、http://example.com/、http://example.com/home.html、http :(s):// example.com/index.html、http:s://example.com/index.htmはすべて404

私は何を試すことができますか?

server { 
    listen 80; 
    server_name example.com; 
    return 301 https://$server_name$request_uri; 
    root /home/ubuntu/mysitedir/; 
    index home.html; 
} 

server { 
    listen 443 ssl; 

    server_name example.com; 
    ssl_certificate /etc/nginx/ssl/example_combined.crt; 
    ssl_certificate_key /etc/nginx/ssl/www.example.com.key; 
    root /home/ubuntu/mysitedir/; 
    index home.html; 

    location /images/ads { 
     alias /home/ubuntu/mysitedir/images/ads/; 
    } 

    location /images { 
     alias /home/ubuntu/mysitedir/images/; 
    } 

    location /static { 
     alias /home/ubuntu/mysitedir/static/; 
    } 

    location/{ 
     alias /home/ubuntu/mysitedir/; 
     include uwsgi_params; 
     uwsgi_pass unix:/tmp/mysitedir.sock; 
    } 
} 

ありがとう:

は、ここに私のconfファイルです。

答えて

0

location /はキャッチオールです。あなたはtry_filesは次のようにディレクティブを試みることができる:

location @wsgisite { 
    include uwsgi_params; 
    uwsgi_pass unix:/tmp/mysitedir.sock; 
} 

location/{ 
    index home.html; 
    try_files $uri $uri/ @wsgisite; 
} 

ベースの場所に入ってくるすべてのものは、まず、それはそれでインデックス(home.html)ファイルで、ファイル、またはディレクトリであるかどうかを確認し、しますそうでなければ、@ wsgisiteに渡します。

これは、nginxがファイルを最初にチェックしてからwsgiブロックに渡すので、これは他の3つのロケーションディレクティブをobseleteにする必要があります。

+0

ありがとうございます。私はそれを試してみました。また、/ home/ubuntu/mysitedir /と/ usr/share/nginx/html /にindex.htmとindex.htmlを置くと、http:s:/example.com/、http:s: /example.com/home.html、http(s)://example.com/index.html、htt(s)p://example.com/index.htmはすべて404です –

+0

@stubblejumperは何に更新されましたか私はうまくいくと思う。 – miah

+0

素晴らしいです。あなたの助けに感謝します。 –

関連する問題