【问题标题】:Nginx - Changing the server root make location root not workingNginx - 更改服务器根目录使位置根目录不起作用
【发布时间】:2016-02-05 09:41:02
【问题描述】:

我正在尝试在我的域上设置 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 它就可以工作...

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

【问题讨论】:

    标签: nginx nginx-location


    【解决方案1】:

    好的,我修好了,感谢这篇文章: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;
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      相关资源
      最近更新 更多