【问题标题】:Nginx different root in locationsNginx不同的根位置
【发布时间】:2014-07-06 13:13:27
【问题描述】:

http://example.com/ 工作正常,但http://example.com/piwik 给我一个 404。 我不明白为什么这个配置在 Nginx 中不起作用。这是我要服务的网站:

/srv
  /blog
    index.php
  /piwik
    index.php

然后是配置文件:

server {
    charset utf8;

    index index.php;
    server_name example.com;
    root /srv/blog;
    client_max_body_size 10M;

    # Deny all ht file useless in nginx
    location ~ /\.ht* {
            deny all;
    }

    location /images {
            alias /srv/blog/images;
    }

    location /piwik {
            index index.php;
            alias /srv/piwik;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ ^(.+?\.php)(/.*)?$ {
        try_files $1 = 404;
        include fastcgi_params;
        fastcgi_param PATH_INFO $2;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

当我在 nginx 中激活调试日志时,我可以看到这条奇怪的线:

2014/05/18 14:27:08 [debug] 19676#0: *1 open index "/srv/piwik/index.php"
2014/05/18 14:27:08 [debug] 19676#0: *1 internal redirect: "/piwik/index.php?"
2014/05/18 14:27:08 [debug] 19676#0: *1 rewrite phase: 1
[...]

我的错误在哪里?

谢谢 ;)

【问题讨论】:

    标签: nginx web location php


    【解决方案1】:

    好的,问题似乎来了

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    

    我删除了这个部分,清理了配置,它可以工作了。所有的配置都是here

    server {
        listen *:443 ssl;
    
        index index.php;
        server_name example.com;
        # We set the default root to /srv/blog
        root /srv/blog;
    
        location / {
            # Get beautiful urls for the blog
            try_files $uri $uri/ /index.php?$args;
        }
    
        location /piwik {
            # alias does not append location path to the filepath
            alias /srv/piwik;
    
            # catch piwik php files and pass it to php-fpm
            location ~ /piwik/(.*\.php)(/.*)?$ {
                include fastcgi_params;
                fastcgi_param HTTPS on;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
            }
        }
    
        # catch php files and pass it to php-fpm
        location ~ (.*\.php)(/.*)?$ {
            include fastcgi_params;
            fastcgi_param HTTPS on;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
    }
    

    【讨论】:

    • 是否可以将“/piwiki”作为参数?类似于 alias /srv/$uri ?
    • piwik 中为 php 文件添加额外的位置对我有用!谢谢!
    猜你喜欢
    • 2017-11-12
    • 1970-01-01
    • 2019-10-09
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多