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

报告相同问题?

悬赏问题

  • ¥15 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败