Nginx - 更改服务器根目录使位置根不起作用

时间:2016-02-05 09:41:03

标签: nginx nginx-location

我试图在我的域上设置phpmyadmin,出于某种原因,我无法获得我想要的服务器根目录。

这不起作用(在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 / share / nginx / html就行了......

你知道发生了什么吗? 谢谢你读我。

1 个答案:

答案 0 :(得分: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;
    }


}
相关问题