Why displaying error ?
I have running other laravel projects fine with laravel 5.2 but i have old project with laravel 4.2 where i am getting this error :
404 File Not Found
You can check error here
On my local pc with php7 fpm working fine using Laravel Valet.
Here is my nginx config file :
server {
listen 80;
server_name blog.yourserviceconnection.com;
root var/www/html/blog/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Looks everything fine to me, and this is .htaccess file :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I saw you are using hhvm so Instead adding.
location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
use
include hhvm.conf
May this will help as it's default configuration by hhvm so no mistake.
Related
In apache I have an .htaccess that will rewrite from http://server/api/any/path/i/want to http://server/api/index.php if no file or folder is found.
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2index.php [L,NC,QSA]
</IfModule>
I'm moving to docker and will use nginx instead and I want to re-write the rewrite.
Important to note is that using apacheand .htaccess $_SERVER['REQUEST_URI'] is /api/any/path/i/want and not the re-written url (index.php....).
I'm not that well versed with nginx but from posts on SO I've figured some things out.
Relevant section of site.conf
location / {
root /app/html;
try_files $uri $uri/ index.html /index.php?$args;
}
location ~ \.php$ {
try_files $uri #missing;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location #missing {
rewrite ^ $scheme://$host/api/index.php permanent;
}
The above config will unfortunately only redirect to index.php and is as far I've managed to get.
How can I do the same thing in nginx?
This is a typical nginx configuration for PHP-FPM.
server {
root /app/html;
location / {
try_files $uri $uri/ /api/index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Notice the differences from your example:
Removed the unnecessary #missing location block.
Removed the try_files statement from the .php location block.
Moved the root declaration to the server block. If you need to have different roots, please specify this in your question.
The only try_files statement includes the full path for your api/index.php.
If a request comes for a non-existing path, it will be handled by your /app/html/api/index.php script, acting as a global entry-point.
Previously I was working with Apache server (I had a special .htaccess) for my router, and everything worked as expected:
request: test.local/index/action was handled by test.local/index.php.
My .htaccess file was:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
The problem: Now, I need to implement same functionality in Nginx. I implement nginx configs for my websites including in main nginx.conf -nginx folder- /include.d/test.conf . I tried this test.conf configuration:
server {
listen 80;
listen [::]:80;
server_name productlocator.local;
root /var/www/test/;
index index.php index.html;
location ~ \.php$ {
# fastcgi_split_path_info ^(.+?\.php)(/.*)$;
try_files $uri $uri/ /index.php?$query_string;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
Requests to test.local/index.php are properly handled, but requests like test.local/index/action result with 404 Not Found error.
The question: How do I configure Nginx for my router to work?
Use
server_name test.local;
instead
server_name productlocator.local;
And then look this link
I have a website set up on Laravel 5.1. It throws a 404 error on any page except the homepage. However, when I add index.php in the URL, it works. My site runs on a Ubuntu machine with Nginx as the web server.
Loads fine: mysite.com/index.php/dashboard
Gives 404: mysite.com/dashboard
My .htaccess in the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Thanks for your time and I would greatly appreciate any help.
Edit:
This is my Nginx conf:
server {
server_name mysite.com;
return 301 $scheme://www.mysite.com$request_uri;
}
server {
listen 80;
server_name www.mysite.com;
# note that these lines are originally from the "location /" block
root /usr/share/web/site/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/web/html;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_max_temp_file_size 0;
fastcgi_buffer_size 4K;
fastcgi_buffers 64 4k;
include fastcgi_params;
}
}
A .htaccess is for Apache. It will not work on Nginx.
Try this in your nginx site configuration (taken from the Laravel documentation.)
location / {
try_files $uri $uri/ /index.php?$query_string;
}
I have a site developed with Laravel on my main route say www.example.com/. I have configured it properly with Nginx and php-fpm. My config is below.
Then I added a blog in route /blog (www.example.com/blog/) and configured it with Nginx alias.
Now the problem is that Permalinks in Wordpress are not working. Nginx redirects to Laravel's 404 page.
For example when user enters some URL like this: example.com/blog/about, Laravel's 404 page shows up which is weird.
How can I fix this? How can I config Nginx? What's Wrong?
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html/;
location /blog {
try_files $uri $uri/ /index.php?$args;
alias /usr/share/nginx/blog/;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx$fastcgi_script_name;
}
}
location / {
root /usr/share/nginx/main_site;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
You do not need to use alias when the location matches the end of the alias path. See this document.
The try_files in location /blog needs to default to the WordPress router (/blog/index.php) and not the Laravel router (/index.php).
Try:
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
root /usr/share/nginx;
...
location ~ \.php$ {
...
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Suppose you are running laravel on your server and you want to use wordpress as a blog. and you installed wordpress in blogs named folder. Then you have to do changes in 3 places
1) laravel .htaccess file
2) blogs folder .htaccess file
3) nginx configuration file
Laravel.htaccess file changes add this line
RewriteCond %{REQUEST_URI} !^/blogs/
blogs folder .htaccess file add this code or modify
RewriteEngine On
RewriteBase /blogs/ # <==== CHANGED LINE!!
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogs/index.php [L] # <==== CHANGED LINE!!!
in nginx configuration file try modify below code in both port 80 and port 443 code block
location /blogs {
try_files $uri $uri/ /blogs/index.php?$args;
set $base /var/www/html;
root $base/public;
location ~ \.php$ {
fastcgi..
}
}
I am trying to convert trivial htaccess file to Nginx and can't make it work. It returns 404 error.
Here is htaccess content:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Here is my current nginx config:
server {
listen 80;
server_name domain.biz;
root /var/www/domain.biz;
charset utf-8;
autoindex off;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/domain.biz$fastcgi_script_name;
}
}
How about other php files you call directly? For example an info.php with just a
phpinfo();
inside?
I ask this because your server conf seems to be using try_files just right, but I'm not sure you're serving php scripts right.
¿Is your fastcgi pool listening on that sock? ¿Are you sure it isn't listening in port 9000 for example? In any case, I prefer to define an upstream in the http section and use it later in the server section
http {
upstream phpbackend {
server unix:/var/run/php5-fpm.sock;
}
...
server {
...
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass phpbackend;
fastcgi_param SCRIPT_FILENAME /var/www/domain.biz$fastcgi_script_name;
}
}
}
Are you sure your php.ini has the cgi.fix_pathinfo set to false?