【问题标题】:Setting proper path in Nginx for Symfony2在 Nginx 中为 Symfony2 设置正确的路径
【发布时间】:2013-06-23 09:33:27
【问题描述】:

我需要将我的 symfony 应用程序安装在与其他 web 应用程序相同的域中,所以我希望它位于 /dev/symfony_app 路径中

我尝试使用NginX Friendly PHP Framework,但那里的解决方案不起作用。

我有这样的 nginx 配置,它也根本不起作用。路径有问题,root 也没有别名指令对我有用。

location /dev/symfony_app/ {
    root /home/.../public_html/web;
}
location ~ ^/dev/symfony_app/(app|app_dev|config)\.php(/|$) {
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    fastcgi_param HTTPS off;
}

nginx错误日志:

请求http://domain.com/dev/symfony_app/

2013/06/23 11:25:31 [error] 22549#0: *668 
"/home/.../public_html/web/dev/symfony_app/index.php"
is not found (2: No such file or directory), client: *,
server: domain.com, request: "GET /dev/symfony_app/ HTTP/1.1", host: "domain.com"

请求https://domain.com/dev/symfony_app

2013/06/23 11:25:37 [error] 22549#0: *668
FastCGI sent in stderr: "Primary script unknown" while 
reading response header from upstream, client: *, server: domain.com,
request: "GET /dev/symfony_app HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/php-fpm.sock:", host: "domain.com"

请求https://domain.com/dev/symfony_app/app_dev.php

2013/06/23 11:27:06 [error] 22549#0: *797 
FastCGI sent in stderr: "Primary script unknown" while 
reading response header from upstream, client: *, server: domain.com, 
request: "GET /dev/symfony_app/app_dev.php HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/php-fpm.sock:", host: "domain.com"

【问题讨论】:

标签: symfony nginx


【解决方案1】:

嗯,你的路径上的点在做什么?你不能有一个名称为三个点的目录(至少这对我来说是新的)。来自 nginx 的错误消息在这方面非常具体。该路径不存在。

server {
    listen 80;
    server_name _;
    root /home/public_html/web;

    location / {
        location ~* ^/dev/symfony_app/(app|app_dev|config)\.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass unix:/var/run/php-fpm.sock;
        }
    }
}

这应该可以解决问题。

Symfony 安装的索引文件的绝对本地路径必须是/home/public_html/web/dev/symfony_app/index.php。对http://example.com/dev/symfony_app 的请求将映射上述位置。

我希望这会有所帮助,否则请发表评论并描述还有什么问题。

【讨论】:

  • 我路径中的点只是删除了用户名。也许我应该在那里设置一些名称以使其清楚。我将在几个小时内检查提出的解决方案,并告知它是否有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-11
  • 1970-01-01
  • 2012-08-27
相关资源
最近更新 更多