如何让 Zend 2 和 Nginx 工作?

如何让 Zend 2 和 Nginx 工作?

我正在尝试让我的 Zend2 应用程序与 Nginx 而不是 Apache 一起工作。

我在 WWW 上搜索解决方案,但没有找到任何有关 Zend 2 和 Nginx 的东西,我找到的只是一些关于如何使旧版 zend (1) 框架与 nginx 协同工作的旧帖子。

与所有新的 zend 2 应用程序一样,我尝试将我的 nginx 配置指向 /projectdir/public,并且尝试了其他几种方法从 /projectdir/public 建立到 /usr/share/nginx/www 的符号链接,但就是不起作用。

PHP5FPM 已安装并配置,phpinfo() 可以工作。

这是我最后一次尝试让事情正常运作的样子......

这是我的 /etc/nginx/sites-available/default

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www/;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #   proxy_pass http://127.0.0.1:8080;    
    #}

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/www;
    #}

    #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/evils/projects/zendCodeGit/public$fastcgi_script_name;
        include fastcgi_params;
    }

}

我已经尝试放置一个具有正确根目录的额外位置 /public/,但我认为我缺少一些配置工作或其他东西。

我已经执行了 php composer.phar install 命令。

操作系统是 Ubuntu 12.04

编辑:

这是最后一个错误日志

    2013/02/09 14:57:47 [error] 10140#0: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'Zend\Uri\Exception\InvalidUriPartException' with message 'Host "_" is not valid or is not accepted by Zend\Uri\Http' in /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Uri/Uri.php:729
Stack trace:
#0 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Http/PhpEnvironment/Request.php(285): Zend\Uri\Uri->setHost('_')
#1 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Http/PhpEnvironment/Request.php(85): Zend\Http\PhpEnvironment\Request->setServer(Object(Zend\Stdlib\Parameters))
#2 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Mvc/Service/RequestFactory.php(38): Zend\Http\PhpEnvironment\Request->__construct()
#3 [internal function]: Zend\Mvc\Service\RequestFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'request', 'Request')
#4 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Serv" while reading response header from upstream, client: 10.211.55.2, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "10.211.55.10"
2013/02/09 14:57:48 [error] 10140#0: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'Zend\Uri\Exception\InvalidUriPartException' with message 'Host "_" is not valid or is not accepted by Zend\Uri\Http' in /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Uri/Uri.php:729
Stack trace:
#0 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Http/PhpEnvironment/Request.php(285): Zend\Uri\Uri->setHost('_')
#1 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Http/PhpEnvironment/Request.php(85): Zend\Http\PhpEnvironment\Request->setServer(Object(Zend\Stdlib\Parameters))
#2 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Mvc/Service/RequestFactory.php(38): Zend\Http\PhpEnvironment\Request->__construct()
#3 [internal function]: Zend\Mvc\Service\RequestFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'request', 'Request')
#4 /home/evils/projects/zendCodeGit/vendor/zendframework/zendframework/library/Zend/Serv" while reading response header from upstream, client: 10.211.55.2, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "10.211.55.10"

答案1

PHP message: PHP Fatal error:  Uncaught exception 'Zend\Uri\Exception\InvalidUriPartException' with message 'Host "_" is not valid or is not accepted by Zend\Uri\Http

Zend 不喜欢你的server_name

server_name _;

将其更改为其他内容,例如“localhost”。

答案2

更通用的解决方案是:

fastcgi_param   SERVER_NAME $host;

这样,SERVER_NAME 实际上会保存请求中的主机标头的值。当您定义了多个服务器名称或使用通配符时,这也很有用

相关内容