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

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

报告相同问题?

悬赏问题

  • ¥50 gki vendor hook
  • ¥15 centos7中sudo命令无法使用
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联