I have the following in `nginx.conf in my project root
location / {
try_files $uri $uri/ /index.php?$query_string;
}
But only in the / path works, all others are coming up with a 404 error.
How can I make Laravel work on heroku with nginx?
This ended up working for me:
Procfile:
web: vendor/bin/heroku-php-nginx -C nginx.conf public/
nginx.conf
location / {
# try to serve file directly, fallback to rewrite
try_files $uri #rewriteapp;
}
location #rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /index.php$1 last;
}
You are missing fastcgi_* directives; try this after your location directive:
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;
}
Source: How to Install Laravel with an Nginx Web Server on Ubuntu 14.04
Related
I've put my Laravel app files into /var/www/html/api/v2directory.
My nginx conf looks like this:
listen 80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-de$
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/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi$
fastcgi_param PATH_INFO $fastcgi_path_info;
}
I want to access my routes like this: [host]/api/v2/[route]
But it is throwing 404 right now except for homepage.
Please let me know what could be wrong here.
Change this line
root /var/www/html;
to
root /var/www/html/..../public;
Then restart nginx
$ sudo systemctl restart nginx
I'm getting a 404 every time I try to open a page other than the welcome page. I've read all the posts here on how to fix the problem, but none of the solutions worked for me.
I'm on Windows 10 and use WPN-XM for the Nginx server.
My laravel project is installed in C:/server/www/myapp
My configuration looks as follows:
server {
listen 127.0.0.1:80;
server_name localhost;
root www;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php_pool;
fastcgi_index index.php;
#fastcgi_param PHP_FCGI_MAX_REQUESTS 1000;
#fastcgi_param PHP_FCGI_CHILDREN 100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
# mitigate namespace conflict, see httpoxy.org
fastcgi_param HTTP_PROXY "";
include fastcgi_params;
}
I tried replacing root www with "C:/server/www/myapp/public" and a couple of other options.
I used try_files $uri $uri/ /index.php$is_args$args instead of try_files $uri $uri/ /index.php?$query_string
Any help will be appreciated.
I have this nginx config.
server {
listen 80;
listen [::]:80;
server_name apps.myapp.com;
root /var/www/apps.myapp.com/public;
index index.php;
location / {
try_files $uri $uri/ index.php?$query_string;
}
}
I have this route:
Route::get('/lead', 'LeadsController#index' );
When I access to http://apps.myapp.com/lead, I get 404.
You can run nginx -t to check if there any error in the file configuration, in addition to that you need to add fastcgi_pass
Below is nginx configuration from my production server
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public/;
index index.php index.html index.htm;
server_name xxx.xxx.xxx.xxx;
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;
}
}
You can read this tutorial is very helpful:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
This is the configuration I use for my Laravel app.
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php?$query_string;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I'm novice and i have a problem with the rewrite mod in NGINX.
I give you the environement:
I have 2 app:
each one www/
another one www/atri/
both app need to be a Mod_rewrite, so i use this :
location / {
try_files $uri $uri/ /index.php?$args;
}
This work completely for the first app, BUT, when I go on the second app /atri/ this load all the app like the same root of the first app in the folder /www/.
Do you have an idea to separate the 2 app in the conf?
For information I use codeigniter.
Thanks for your reply.
Try:
location / {
try_files $uri $uri/ /index.php?$args;
}
location /atri {
try_files $uri $uri/ /atri/index.php?$args;
}
See this document for more.
location /atri/ {
alias /var/www/html/atri/;
try_files $uri $uri/ /atri/index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
try this!
I have the following nginx configuration for the url rewrite
location / { ##merge
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location /devtools/phpmyadmin/ { ##merge
root /var/www/domain.tld/web;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
in the /var/www/domain.tld/web/ directory have an /api/ directory and I want disable for the url rewrite for this. So if I woud like access from url with index.php: http://domain.tld/api/index.php/function/method
How can I modify the nginx config file?
Edit:
I try the following rewrite, but not working:
location = /api {
rewrite ^ /api/index.php;
}
I confess that I do not understand your configuration file. Generally, you would define a root to be inherited by all (or most) of your location blocks. And usually a separate location ~ \.php$ block to handle off-loading .php scripts to a PHP processor via FastCGI.
Ignoring your location /devtools/phpmyadmin/ block for the moment, a typical implementation would look like this:
root /var/www/domain.tld/web;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
The nginx directives are documented here.
If you want URIs that begin with /api to use a different controller, you could add:
location /api {
try_files $uri $uri/ /api/index.php;
}
I cannot see the purpose of the location /devtools/phpmyadmin/ block, as it does not seem to add any more functionality.