dongzhi6927
2016-08-24 06:55 阅读 50
已采纳

使用Vagrant运行Symfony应用程序

I try to run Symfony app with Vagrant, I install Vagrant, copy Symfony app in Vagrant folder (vagrantrasmus/clientproject) I add in hosts 192.168.7.7 clientproject and I add in client.conf from conf.d

server {
    server_name clientproject;
    root /vagrantrasmus/clientproject/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
      return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

But, don't work, i received 502 Bad Gateway.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douchu4048 douchu4048 2016-08-24 08:43

    I change the content of client.conf in

    server {
        listen       80;
    
        server_name  localhost;
        #root   /var/www/default;
        root   /var/www/default/clientproject/web
        index  index.php index.html index.htm;
        access_log  /var/log/nginx/default-access.log  main;
        error_log   /var/log/nginx/default-error.log;
    
        error_page   500 502 503 504  /50x.html;
    
        location = /50x.html {
            root   /var/www/default;
        }
    
        location / {
            #try_files $uri /app_dev.php$is_args$args;
            try_files $uri $uri/ @rewrite;
        }
        location @rewrite {
            rewrite ^(.*)$ /index.php;
        }
    
        location ~ \.php {
            include                  fastcgi_params;
            fastcgi_keep_conn on;
            fastcgi_index            index.php;
            fastcgi_split_path_info  ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
            fastcgi_pass unix:/var/run/php-fpm.sock;
        }
    }
    

    And i have in logs

    ==> /var/log/nginx/default-error.log <==
    2016/08/24 08:42:52 [error] 26472#0: *57 connect() to unix:/var/run/php-fpm.sock failed (111: Connection refused) while connecting to upstream, client: 192.168.7.1, server: clientproject, request: "GET /app_dev.php/translation HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "clientproject"
    
    ==> /var/log/nginx/default-access.log <==
    192.168.7.1 - - [24/Aug/2016:08:42:52 +0000] "GET /app_dev.php/translation HTTP/1.1" 502 537 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" "-"
    
    点赞 评论 复制链接分享

相关推荐