Nginx on Ubuntu Server throws 404 not found - laravel

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!

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.

Endless loading/spinner on the woocommerce checkout page

Since some recent updates , the checkout page on my site is not working. Even after entering name/address, the area under “Your order” is greyed out and spinning.
Things I’ve tried that didn’t work:
Disabled all plugins (except woocommerce)
Changed theme to Default theme.
Checked Woocommerce>System Status.
Increased memory limit via wp-config Disabled PayPal (the only payment gateway)
Removed the woocommerce files via admin and
uploaded a fresh version via FTP
Checked items on this page: http://docs.woothemes.com/document/endless-
loadingspinner-on-the-checkout-page/
I'm runngin NGINX 1.6.3 server and seems to be no issue with server as other woocommerce sites on same server works fine.
I’ve looked at the Chrome console and found this:
https://example.com/?wc-ajax=get_refreshed_fragments Failed to load resource: the server responded with a status of 405 (Not Allowed)
I checked using full URL like https://example.com/index.php?wc-ajax=get_refreshed_fragments and it shows some ajax code but using https://example.com/?wc-ajax=get_refreshed_fragments shows homepage.
Disabling Ajax completely on checkout page works but it does not update price for checkout addons like gift wrap.
This is config for my site:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl spdy;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
server_name example.com www.example.com;
root /home/user/example.com/public/;
index index.php;
access_log /home/user/example.com/logs/access.log;
error_log /home/user/example.com/logs/error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ /.well-known {
allow all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm: fastcgi_pass
#unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

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';
});

Hosting Laravel Application on Ubuntu Server

I have recently developed my first Laravel application (version 5.2.).
I now want to host the application on my client's server running Ubuntu.
Their admin managed to install and run the native Laravel application on the server which works just fine, however when I come to copy and paste my own application over, the browser returns:
403 Forbidden
nginx/1.4.6 (Ubuntu)
Accessing the public folder directly (www.example.com/public/index.php) the browser returns:
The www.example.com page isn’t working
www.example.com is currently unable to handle this request.
HTTP ERROR 500
Can anybody please help me out with the proper method of hosting my application?
Seems more like an nginx-problem. Try to change your nginx virtualhost config to this.
server {
listen 80;
server_name yoursite.tld
root /var/www/yoursite/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
First save your file inside,
var/www/html/
Then using Terminal go to your folder
cd var/www/html/your_folder
Run Laravel application
sudo php -S localhost:8888 -t public
Make sure your port number is not same as the other Laravel instance running in the server.

Heroku Nginx HTTP 413 entity too large

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.

Resources