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 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 Spring MVC项目,访问不到相应的控制器方法
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on 192.168.154.223发生意外错误: 5无法连接到 MQTT 代理,如何解决?
  • ¥15 关于#genesiscsheel#的问题,如何解决?
  • ¥15 Android aidl for hal
  • ¥15 STM32CubeIDE下载程序报错
  • ¥15 微信好友如何转变为会员系统?(相关搜索:小程序)
  • ¥15 c# 直接使用c++ 类库文件
  • ¥15 一个主机电脑有两个显示器,当前有两个软件主体是网页html打包的exe程序,如何通过cmd命令bat同时打开软件一个在主屏幕显示,另外一个软件在2副屏幕上显示