Heroku Nginx HTTP 413 entity too large - heroku

I'm getting error 413 when uploading a 4MB file. I have already created a .user.ini file on the public/ folder. to allow up to 10 MB files
So I used client_max_body_size like this on my nginx.conf, but I still get 413.
location / {
index index.php;
try_files $uri $uri/ /index.php?$query_string;
client_max_body_size 10M;
}
That configuration is because I'm using Laravel 5.
This is my Procfile
web: vendor/bin/heroku-php-nginx -C nginx.conf public/
Did I do something wrong?

Perhaps a bit late, but in order to fix this, move your client_max_body_size 10M; outside of the location section. Like this:
client_max_body_size 10M;
location / {
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
See https://github.com/heroku/heroku-buildpack-php/blob/beta/conf/nginx/heroku.conf.php#L35 for reference on how heroku includes this file.

Related

How To Deploy Laravel Application on Nginx Ubuntu 16.04 Server?

I want to deploy simple laravel app on nginx ubuntu 16.04 server .
I have put my app inside /var/www/html folder
on my server , i have already setup php and mysql .
i have added below code in my /etc/nginx/sites-enabled/myapp.com
server {
listen 80;
listen [::]:80;
root /var/www/html/MyApp/public;
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;
server_name myapp.com;
error_log /var/log/nginx/myapp.com.log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =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;
}
location ~ /\.ht {
deny all;
}
}
but instead of running app , it is downloading file , so i have searched and found stackoverflow link :
Nginx serves .php files as downloads, instead of executing them
But this in Not working in my case .
I have not much idea about nginx , please help me .
nginx will show error 502 (bad gateway) when php-fpm is not running or it can't find the socket.
In your case, I think the problem is on this line:
fastcgi_pass unix:/run/php/php7.0.22-fpm.sock;
try changing it to
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
save and reload or restart nginx.

Laravel 4.2 on Nginx getting 404 (VPS)

I'm trying to use the Laravel 4.2 on nginx. I have a VPS (Dreamhost) and I put the Laravel framework inside the root path of user (/home/vi360/) and the public path is on /home/vi360/vide360.com.br
I've been researching several ways to set up nginx for Laravel, but I'm not getting any success. Only the home page is opening (www.vide360.com.br), but all the other pages (directed by /home/vi360/app/routes.php) are returning with error 404.
I have created the /home/vi360/nginx/vide360.com.br/vide360.conf as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/vi360/vide360.com.br;
index index.php index.html index.htm;
server_name [server ip address];
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
What am I maybe doing wrong?
I guess you changed the public folder name.
Laravel looks up its files in public folder. Say your laravel application running on /home/vi360 then your public folder path will be /home/vi360/public.
Then on your nginx, it should be like
root /home/vi360/public;
Try renaming the vide360.com.br folder back to public and it will be fine. This is because the framework follows the request by booting up and forwarding it to public/index.php file.
Don't forget to restart nginx and php-fpm after the settings change.
EDIT
If the developer wants to change the public directory of laravel from public folder to other folder, say vide360.com.br, then edit your Application Service Provider (ASP) which is located at App\Providers\AppServiceProvider.php. And under the register method add the code with your new public folder name.
$this->app->bind('path.public', function() {
return base_path().'/vide360.com.br';
});

Laravel 5/ 5.4 paginator is not working in NGINX production environement

In my local environment i did $items = Model::paginate(10); and it worked. Then i pushed it to production and when i click on the pagination links it displays page 1 again and again. then i did dd($items). i found that the current Page property of length aware pagination is not changing when i change the address to /items?page=*. How to make current page property change accordingly or there is some thing else? thanks in advance
I am using ubuntu 16.04 nginx server. The problem was that $_GET session variables were not being set properly. so what I did was inside /etc/nginx/sites-available/default and inside location / block/ directive I changed try_files $uri $uri/ /index.php?$query_string; to try_files $uri $uri/ /index.php?$args; and it worked. Or see Laravel 5 - NGINX Server Config Issue with URL Query Strings
Awsome Thanks #Ahmed
I just had to change mine from
location / {
try_files $uri $uri/ /index.php?$query_string;
}
to
location / {
index index.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
as i saw some of my other sites was using the #rewriteapp part and seem to work fine.

Nginx on Ubuntu Server throws 404 not found

After rebooting the laravel-based website on a Ubuntu server using nginx, and configured everything properly (hopefully, at least it worked before), I can only access to the index page but not any other page - nginx keeps throwing 404 not found.
Thought it could be permission issue but I've already tried
sudo chown -R :www-data /var/www/foo-bar
sudo chmod -R 775 /var/www/foo-bar/storage
sudo chmod -R 775 /var/www/foo-bar/resources
But seems not helping. And here is my nginx config file:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/foo-bar/public;
index index.php index.html index.htm;
server_name 120.25.203.113;
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:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Any idea?
(Try http://120.25.203.113/ and click on the center button to have a look if interested!)
Update: the error log shows
[error] 24119#0: *77 open() "/var/www/ozunimate/public/student/register" failed (2: No such file or directory), client: 14.202.230.9, server: 120.25.203.113, request: "GET /student/register HTTP/1.1", host: "120.25.203.113", referrer: "http://120.25.203.113/"
"student/register" is not under /public and should be redirected (it used to be redirected normally before rebooting). Seems redirect not working anymore.
Let me answer my question.
All the configs are fine - it turned out that the autoloader is not working. See in the error log nginx didn't redirect http requests to the right directories. It should be working fine, but I guess it's polluted somehow during rebooting.
Solution:
1. in the remote server: composer install
2. if not working, simply restore the entire server and boot again. It's a booting problem anyway.
That might be right. However for me I was missing the following:
location / {
# This line
#try_files $uri $uri/ /index.php$is_args$args;
# OR this
try_files $uri $uri/ /index.php?$query_string;
}
That solved the problem!

nginx not passing off rewrites to php

Here are the pertinent lines of my nginx.conf file.
location / {
try_files $uri $uri/ /index.php #rewrite;
}
location #rewrite {
rewrite ^/customer/(.*)$ /customersDisplay.php?id=$1;
rewrite ^/attc2/(.*)$ /usr/www/vault/$1;
rewrite ^/xport/(.*)$ /usr/www/files/innoMatrix/xport/$1;
rewrite ^/forms/(.*)$ /usr/www/files/innoMatrix/forms/$1;
rewrite ^/grafx/(.*)$ /usr/www/files/innoMatrix/grafx/$1;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DATABASE innoMatrix;
include fastcgi_params;
}
Can anyone right off had see why customer wouldnt be handed off to the fpm socket? It redirects properly, but downloads the file instead of interpreting it in PHP. I use a nearly identical config for my phalcon based app and it works a champ.
I strongly recommend learning how to debug nginx rewrites by turning on rewrite_log on. If you did that you'd almost certainly see that what is happening is that:
Request to '/customer/foo' comes in.
It doesn't match a file in the first location block, so gets tried through the #rewrite block.
The #rewrite block rewrites the request to /customersDisplay.php?id=foo and restarts the processing the request.
The first location block now tries the file /customersDisplay.php and it exists, so it gets served as the file.
Putting it as gently as I can, the way you've written your nginx conf is 'against common practice for nginx', aka don't do it like that.
You presumably are migrating from, or have used Apache rewrite in the past, and are using the same style of rewrites in Nginx. You almost certainly don't need to use the for mapping requests to PHP.
I suggest, first just copying the file fastcgi_params to fastcgi_php_params and including the other proxy settings in there, (to avoid duplication) and then modifying your nginx config to look something like:
#Mapping external URL to internal file path
rewrite ^/attc2/(.*)$ /usr/www/vault/$1;
rewrite ^/xport/(.*)$ /usr/www/files/innoMatrix/xport/$1;
rewrite ^/forms/(.*)$ /usr/www/files/innoMatrix/forms/$1;
rewrite ^/grafx/(.*)$ /usr/www/files/innoMatrix/grafx/$1;
#All requests below 'customer' are fed to PHP
location ~ /customer/(.*)$ {
try_files $uri $uri/ /customersDisplay.php?id=$1 =404;
include fastcgi_php_params;
}
#Try and serve all other static files directly, if they exist.
location ~* ^[^\?\&]+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|svg|woff|ttf)$ {
try_files $uri /index.php?file=$1;
#access_log off;
expires 24h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
#final catch all location, pass all remaining requests to PHP.
location / {
try_files $uri $uri/ /index.php =404;
include fastcgi_php_params;
}

Resources