Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Nginx & Symfony3] Impossible d'accéder au vhost

Sujet résolu
    25 mai 2017 à 14:29:44

    Bonjour à tous !

    Je suis passé il y a peu sur une distribution Linux qui est ElementaryOS. Pour tester mes sites sur ma machine, j'ai installé Nginx avec php7. J'ai donc suivi la documentation de Symfony et Nginx en créant un fichier dans le dossier /etc/nginx/sites-available que j'ai relié au dossier sites-enabled grâce à un lien.

    Le problème est que Nginx me renvoie toujours sur la page d'accueil "Welcome to nginx!" alors que j'ai configuré un vhost pour symfony de la manière suivante : 

    server {
        listen 80;
        server_name projet.loc www.projet.loc;
        root /var/www/projet/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/php/php7.0-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;
        }
    
       # 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;
    }
    

    J'ai bien sûr ajouté le "projet.loc" dans mon fichier hosts de Linux.

    Auriez-vous une idée d'où celà peut-il venir ?

    Merci d'avance pour vos réponses 

    UPDATE / SOLUTION :

    server {
        listen 80;
        server_name projet.loc www.projet.loc;
        root /var/www/projet/web;
    
        location / {
            # try to serve file directly, fallback to app.php
            try_files $uri /app_dev.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/php/php7.0-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;
        }
    
       # 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;
    }

    Finalement, la solution était simple : j'utilise un environement de développement donc il faut mettre app_dev.php à la place de app.php (l. 8)

    -
    Edité par Torvald 25 mai 2017 à 16:58:08

    • Partager sur Facebook
    • Partager sur Twitter
    Peut importe ce que disent les autres, vous serez toujours critiqué de toute façon ! - C'est de moi, et je ne suis pas philosophe

    [Nginx & Symfony3] Impossible d'accéder au vhost

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown