By Sayful Islam
I am new user on nginx. I am trying to create a server block for using Laravel 5.2 but I am getting 502 Bad Gateway. Maybe I am doing something wrong. I am using Ubuntu 16.04, PHP 7 and nginx 1.10.0. My config file as bellow:
server {
listen 80;
listen [::]:80;
root /var/www/kneelam.dev/public;
index index.php index.html index.htm;
server_name kneelam.dev www.kneelam.dev;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Well! there is a simple solution for this. Launch your DigitalOcean server with Cloudways. The complete Nginx stack will be built in few clicks along with the Laravel application :)
To simplify the php-fpm configuration, I’d use TCP connections instead of sockets as permissions on the sock file will result in connections errors (and the majority of guides never mention this - so it’s nothing you did).
From the command line:
/etc/php/7.0/fpm/pool.d/www.conflisten = /etc/php/7.0/fpm/pool.d/www.conflisten = 127.0.0.1:9000php-fpm by running service php70-fpm restartYou may need to adjust these paths a bit depending on how you installed PHP, though if you cd /etc/php and run ls -al, you can check whether it’s 7 or 7.0 for your installation.
Now, in the same server block you posted:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;fastcgi_pass 127.0.0.1:9000;Unless you’re explicitly using IPv6 to connect and know for a fact that IPv6 is enabled, I’d also remove:
listen [::]:80;…as it will cause NGINX to fail if not enabled, not supported, etc.
Now run:
service nginx restart…and see if you’re able to connect. If not, then we need to take a look at the error logs to see if there’s something more explicit being logged to detail what’s happening.
By default, the error log is located at /var/log/nginx/error.log so we’d run:
tail -50 /var/log/nginx/error.logWhich will output the last 50 lines of the log (or all lines if there’s less than 50). If you would copy and paste that here, I’ll be more than happy to take a look at it for you. If you’d like, feel free to change instances of your domain or IP to filler data.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.