dongzhi6927 2016-08-24 06:55
浏览 51
已采纳

使用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 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" "-"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏