2016-10-11 84 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。 –