douyu3145 2016-12-27 20:48
浏览 63
已采纳

NGINX服务器配置

I am trying to configure nginx and have the following configuration in:

/etc/nginx/sites-enabled/default

server {
    server_name firstproj.dev www.firstproj.dev;
    root /var/www/firstProj/web;

    location / {
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }

    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
      return 404;
    }

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

where both app.php and app_dev.php are files in /var/www/firstProj/web/ folder created by symfony with no further modifications.

firstProj is a symfony project that I am currently working on and what I fail to understand here is:

  1. Why when i access www.firstproj.dev I get

    Oops! An Error Occurred The server returned a "500 Internal Server Error".

  2. Why when I access www.firstproj.dev/app_dev.php everything is ok and I can also access my routes (eg: www.firstproj.dev/app_dev.php/homepage works perfectly fine and returns the expected response from the action in my controller)

  3. Why when I access www.firstproj.dev/app.php I get 404 error.

I want it to work with www.firstproj.dev/homepage with no app_dev.php there but I cannot make it work that way. Furthermore, if I access

http://localhost

I get:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.

Thank you for using nginx.

I apologize if this is a rather dumb question but I'm a beginner as far server configuration is concerned.

Thank you!

  • 写回答

1条回答 默认 最新

  • dsvd407787736 2016-12-28 00:04
    关注

    So you're finding that your app_dev.php works but app.php does not work?

    I've had this happen in the past and there are a few things worth checking.

    1. Copy the contents of app_dev.php into app.php and see if www.firstproj.dev/app.php or www.firstproj.dev work. If it works then you know it's not a problem with NGINX but instead a problem with your Symfony Setup.

    2. Have you created a cache or logs directory for prod or only for dev? Are they writable by www-data?

    3. Have you checked /var/log/nginx/project_error.log to see if any error is showing up when trying to access app.php?

    4. At the top of the app.php file add in the line error_reporting(E_ALL);. Now when you try to access the production version do you see any error?

    5. Try clearing the cache for production. Depending how you have you server setup (Are you using ACL or CHOWN/CHMOD for your cache/log files?) You can run something like sudo su -u www-data php bin/console cache:clear --env prod

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题