2016-02-05 116 views
0

我試圖在我的域上設置phpmyadmin,並且出於某種原因,我不能擁有我想要的服務器根目錄。Nginx - 更改服務器根目錄使位置根目錄不起作用

(上example.com/phpmyadmin 404沒有在日誌中的任何東西)

這不起作用:

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 
    client_max_body_size 300m; 
    root /var/www/html; 
    index index.php index.html index.htm; 

    server_name example.com; 

    location/{ 
     try_files $uri $uri/ =404; 
    } 

    location /phpmyadmin/ { 
     root /var/www/admin/; 
    } 

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

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

但是,如果我改變了服務器的根目錄爲/ usr /共享/ nginx的/ HTML它的工作原理。 ..

你知道發生了什麼嗎? 謝謝你的閱讀。

回答

0

好吧我固定它,多虧了這個帖子:nginx configuration with multiple location blocks

的原因是〜位置PHP文件...

因此,這裏的工作代碼:

server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 
    client_max_body_size 300m; 
    root /var/www/html; 
    index index.php index.html index.htm; 

    server_name example.com; 

    location/{ 
     try_files $uri $uri/ =404; 
    } 

    location /phpmyadmin/ { 
     root /var/www/admin/; 
location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
    } 

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


}