2015-06-25 48 views
0

我正在嘗試配置nginx,以便在去http://example.com/~user/時,它會從/home/~user/www/目錄加載文件。Nginx用戶主頁目錄

我發現了一個腳本,似乎適用於.html文件,但在.php文件上返回404錯誤。我認爲它可能與我的conf文件中的另一個塊有關,但我不確定問題是什麼。

//nginx config 

server { 
listen  80; 
server_name example.com; 

root /home/example.com/www; 
index index.php index.html index.htm; 

location/{ 
    try_files $uri $uri/ =404; 
} 
error_page 404 /404.html; 
error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root /home/example.com/web; 
} 

///// 
//user home directory code 

location ~ ^/~(.+?)(/.*)?$ { 
    alias /home/$1/www$2; 
    autoindex on; 
    index index.php index.html 
} 

//// 

location ~ \.php$ { 
    try_files $uri =404; 
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 
} 

回答

0

我決定使用Apache,因爲這個服務器需要的複雜性和邏輯。 Nginx是一款出色的服務器,但不適合我的需求。