• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Problem z konfiguracją symfony na NGINX

Object Storage Arubacloud
0 głosów
374 wizyt
pytanie zadane 31 sierpnia 2018 w PHP przez misiek.sz Bywalec (2,050 p.)

Witam,

próbuję wgrać projekt symfony 4 na serwer produkcyjny z nginx ale po konfiguracji serwera pod symfony wyświetla się w przeglądarce komunikat "Ta strona nie działa, serwer nie może teraz obsłużyć tego zadania, HTTP ERROR 500".

Poniżej konfiguracja serwera:

 

server {
 listen 80 default_server;
 listen [::]:80 default_server;

 # SSL configuration
 #
 # listen 443 ssl default_server;
 # listen [::]:443 ssl default_server;
 #
 # Note: You should disable gzip for SSL traffic.
 # See: https://bugs.debian.org/773332
 #
 # Read up on ssl_ciphers to ensure a secure configuration.
 # See: https://bugs.debian.org/765782
 #
 # Self signed certs generated by the ssl-cert package
 # Don't use them in a production server!
 #
 # include snippets/snakeoil.conf;

 root /var/www/html/wbr/public;

 # Add index.php to the list if you are using PHP
 # index index.php index.html index.htm index.nginx-debian.html;

 server_name 147.135.111.111 www.147.135.111.111;

 location / {
 # First attempt to serve request as file, then
 # as directory, then fall back to displaying a 404.
    try_files $uri /index.php$is_args$args;
 }

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 
 location ~ ^/index\.php(/|$) {
 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
 fastcgi_split_path_info ^(.+\.php)(/.*)$;
 include fastcgi_params;

        # optionally set the value of the environment variables used in the application
        # fastcgi_param APP_ENV prod;
        # fastcgi_param APP_SECRET <app-secret-id>;
        # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

        # 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/index.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;

 
 #location ~ \.php$ {
 #include snippets/fastcgi-php.conf;

 # With php7.0-cgi alone:
 # fastcgi_pass 127.0.0.1:9000;
 # With php7.0-fpm:
 #fastcgi_pass unix:/run/php/php7.2-fpm.sock;
 #}

 # deny access to .htaccess files, if Apache's document root
 # concurs with nginx's one
 #
 #location ~ /\.ht {
 #  deny all;
 #}
}

i zmienna środowiskowa:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/var/www/html/wbr/bin/"
 APP_ENV=prod
 APP_DEBUG=0
 APP_SECRET=123123123123123123
 DATABASE_URL=mysql://michal:pass@127.0.0.1:3306/wbr
 MAILER_URL=smtp://mail.wbr.pl:25?username=biuro@domain.pl&password=pass1&encryption=&auth_mode=login

po raz pierwszy konfiguruję swój serwer i wgrywam projekt symfony, więc bardzo proszę o pomoc

1 odpowiedź

0 głosów
odpowiedź 31 sierpnia 2018 przez efiku Szeryf (75,160 p.)
Pierwsza sprawa to czy ten name server jest na pewno poprawny? Jak chcesz po ip to nie www.ip. w server_name daj nazwę swojej domeny lub sam ip.

Czy na pewno masz otwarty socket o takiej nazwie co masz PHP fpm?

A najlepiej to wyświetl sobie zawartość tego pliku:

error_log /var/log/nginx/project_error.log

Będziesz wiedział co jest źle.
komentarz 31 sierpnia 2018 przez misiek.sz Bywalec (2,050 p.)
edycja 31 sierpnia 2018 przez misiek.sz

taki błąd:

2018/08/31 21:17:07 [error] 8039#8039: *56 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught RuntimeException: APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Com$
Stack trace:                                                                                                                                                                                                                                                           
#0 {main}                                                                                                                                                                                                                                                              
  thrown in /var/www/html/wbr/public/index.php on line 13" while reading response header from upstream, client: 156.67.127.227, server: 147.135.211.105, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "147.135.211.105"0"
        

myślałem że zmienną środowiskową skonfigurowałem bo bin/console mi działa

komentarz 31 sierpnia 2018 przez efiku Szeryf (75,160 p.)
Zmienne środowiskowe nie będą działać na web server, ale w konsoli już tak.

Sprawdź sobie to: https://symfony.com/doc/current/configuration/external_parameters.html#configuring-environment-variables-in-production

Dla nginx masz tam opcje. ;)
komentarz 1 września 2018 przez misiek.sz Bywalec (2,050 p.)
edycja 1 września 2018 przez misiek.sz

ok dodałem mam taką konfigurację:

 

server {
    server_name 147.135.211.105;
    root /var/www/html/public;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        # optionally set the value of the environment variables used in the application
        fastcgi_param APP_ENV prod;
        # fastcgi_param APP_SECRET <app-secret-id>;
        # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

        # 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/index.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;
}

i teraz wyskakuje w przeglądarce: 

Oops! An Error Occurred

The server returned a "500 Internal Server Error".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

komentarz 1 września 2018 przez efiku Szeryf (75,160 p.)
Czytaj logi. Po to masz error_log żeby wiedzieć dlaczego jest problem.
komentarz 4 września 2018 przez misiek.sz Bywalec (2,050 p.)
mam cały czas error 500 a w logach nginx nic się nie zapisuje gdzie moge jeszcze sprawdzić jakieś błędy?

Podobne pytania

0 głosów
0 odpowiedzi 119 wizyt
pytanie zadane 13 lutego 2020 w Systemy operacyjne, programy przez michal_php Stary wyjadacz (13,700 p.)
0 głosów
0 odpowiedzi 135 wizyt
pytanie zadane 31 marca 2020 w Sieci komputerowe, internet przez michal_php Stary wyjadacz (13,700 p.)
0 głosów
1 odpowiedź 534 wizyt
pytanie zadane 1 stycznia 2019 w Hostingi, domeny, usługi przez PelikanFix16 Użytkownik (950 p.)

92,568 zapytań

141,420 odpowiedzi

319,620 komentarzy

61,954 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...