2016-02-05 121 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; 
    } 


}