2016-10-11 96 views
0

我試圖讓http://example.com服務於/home/ubuntu/mysitedir/home.html的http://example.com/home.htmlnginx根指令導致404

我有以下conf文件,它將所有內容成功重定向到https和代理到uwsgi。 http-> https重定向工作正常,並且uwsgi代理可以工作,但http(s)://example.com/,http(s)://example.com/home.html,http(s):// example.com/index.html和http(s)://example.com/index.htm都是404

任何指針,我可以嘗試什麼?

這裏是我的conf文件:

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; 
    } 
} 

感謝。

回答

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。

這也應該使其他三個位置指令obselete,因爲nginx將在傳遞給wsgi塊之前首先檢查文件。

+0

感謝miah。我試過了,無論有沒有root指令都無濟於事。此外,如果我將index.htm和index.html放在/ home/ubuntu/mysitedir /和/ usr/share/nginx/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

它很好用。感謝你的幫助miah。 –