Waik's avatar
Level 1

Laravel nginx

I am creating a new Laravel project on VPS. I use faspanel to manage the server. Tell me how to correctly configure nginx? Now when loading the site, I download the main page as a file. As I understand it, php does not work p/s/ I hid the values of ip and domain.

server {
    server_name domain.my www.domain.my  ;

    listen ip_server:80;

    charset utf-8;

    set $root_path /var/www/fastuser/data/www/domain.my/public;
    root $root_path;
    
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
 
    index index.php;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
 
    error_page 404 /index.php;
 
    
    location ~ /\.(?!well-known).* {
        deny all;
    }
    
    location @fallback {
        proxy_pass http://127.0.0.1:81;
        proxy_redirect http://127.0.0.1:81/ /;
        include /etc/nginx/proxy_params;
    }

    include "/etc/nginx/fastpanel2-sites/fastuser/domain.my.includes";
    include /etc/nginx/fastpanel2-includes/*.conf;
    error_log /var/www/fastuser/data/logs/domain.my-frontend.error.log;
    access_log /var/www/fastuser/data/logs/domain.my-frontend.access.log;
}

When adding a block:

   location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

I get a error

Frontend:Runtime error: unable to execute: "/usr/sbin/nginx '-t' '-c' '/tmp/nginx586624422'"
 stdout: ''
 stderr: 'nginx: [emerg] open() "/tmp/fastcgi_params" failed (2: No such file or directory) in /tmp/nginx586624422:38
nginx: configuration file /tmp/nginx586624422 test failed
'
 description: 'Runtime error: unable to execute: "/usr/sbin/nginx '-t' '-c' '/tmp/nginx586624422'"
 stdout: ''
 stderr: 'nginx: [emerg] open() "/tmp/fastcgi_params" failed (2: No such file or directory) in /tmp/nginx586624422:38
nginx: configuration file /tmp/nginx586624422 test failed
'
 description: 'exit Status: 1''

nginx config

<Directory /var/www/fastuser/data/www/domain.my>
    Options +ExecCGI -Indexes  
    AllowOverride All
</Directory>
<VirtualHost 127.0.0.1:81>
    ServerName domain.my
    ServerAlias www.domain.my  
    DocumentRoot "/var/www/fastuser/data/www/domain.my"
    DirectoryIndex index.php index.html

    CustomLog /var/www/fastuser/data/logs/domain.my-backend.access.log combined
    ErrorLog /var/www/fastuser/data/logs/domain.my-backend.error.log


    <FilesMatch "\.ph(p[3-5]?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
<IfModule php5_module>
        php_admin_flag engine on
    </IfModule>
    <ifModule mpm_itk_module>
        AssignUserId fastuser fastuser
    </ifModule>

    php_admin_value date.timezone "Europe/Moscow"
    php_admin_value display_errors "off"
    php_admin_value log_errors "On"
    php_admin_value mail.add_x_header "On"
    php_admin_value max_execution_time "120"
    php_admin_value max_input_vars "10000"
    php_admin_value opcache.blacklist_filename "/opt/opcache-blacklists/opcache-*.blacklist"
    php_admin_value opcache.max_accelerated_files "100000"
    php_admin_value output_buffering "4096"
    php_admin_value post_max_size "100M"
    php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f '[email protected]'"
    php_admin_value session.save_path "/var/www/fastuser/data/tmp"
    php_admin_value short_open_tag "On"
    php_admin_value upload_max_filesize "100M"
    php_admin_value upload_tmp_dir "/var/www/fastuser/data/tmp"
    ServerAdmin [email protected]

    AddDefaultCharset UTF-8
</VirtualHost>
0 likes
1 reply
Waik's avatar
Waik
OP
Best Answer
Level 1

Resolved! Need to change the phpmode in the site settings (or when creating it in fastpanel) to - php-FPM

1 like

Please or to participate in this conversation.