How to configure vue and laravel into nginx sub directory? - php

How to configure vue and laravel into nginx sub directory?
here is my configuration, is there something wrong with the nginx configuration
location ^~ /vue {
root /var/www/vue-laravel/;
index index.php;
try_files $uri $uri/ /vue/index.php;
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}

Related

Nginx setup for laravel project, which has routes with ".php" endings

I'm trying to setup my Laravel project using Nginx. My /etc/nginx/conf.d/default.conf is:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
I have a problem with routes with ".php" endings, e.g.
Route::get('modules.php', 'ModuleController#index');
Instead of going to index.php and looking there the route, the server tries to open file modules.php, which doesn't exist.
I know, that problem in nginx settings, but I don't have experience with it, so I can't fix it myself.
Look through this page https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04
Here you can find suitable configuration and description.
For example:
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 server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Add a try_files statement to the second location block.
For example:
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
try_files $uri /index.php?$args;
fastcgi_pass app:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

nginx - codeigniter 404 error for all urls

I have uploaded my files(Codeigniter Framework) in abcd directory ( url : example.com/abcd ) . All the links inside give 404 error . For removing index.php, I have placed this nginx.conf file in my root directory ( on server : /.../abcd/)
Here is the code for the nginx.conf file :
server {
server_name example.com/abcd;
root /..../abcd;
index index.html index.php index.htm;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file exists, or route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass example.com/abcd;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
In apache, it was easy using rewrite, i am now stuck with nginx. Please help, I am using nginx for the first time
Try below code.. taken from
https://serverfault.com/questions/695521/codeigniter-in-subdirectory-on-nginx-404
location /abcde/ {
alias /var/www/abcde/;
try_files $uri $uri/ /abcde/index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass backend;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}

laravel inner pages are not working on AWS EC2 Nginx

I am working on a laravel V5.1.11 site which is hosted on AWS EC2 ubuntu with ngnix server. I successfully setup the site but my inner page are not working.
Config is:
server {
listen 82;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 83;
server_name www.example.com;
root /home/in4matic/example-website-dev/public;
location / {
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
How can I fix that.
Moving laravel app from apache to nginx doesn't require many modification, but because laravel uses .htaccess file for url rewrite which won't work in nginx, you have to modify nginx config file so nginx can rewrite url. here is the example of my config file :
server {
listen 80;
server_name your-website.com;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000 # Keep this as per your old config;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I have been using this config for all of my laravel app.
and make sure that Storage directory has proper permission.

Windows Nginx Inuput File not specified error

PROBLEM: Problem i am facing is when I open localhost/phpmyadmin it gives me "No Input file Specified"
I am trying to configure Nginx and php on Windows.
Nginx installed path is E:\server\nginx
php installed path is E:\server\php
PhpMyAdmin installed path is E:\phpmyadmin\
My Root directory path is E:\server\www
Following code is from nginx.conf file.
server {
listen 80;
server_name localhost;
root E:\server\www;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /phpmyadmin/ {
alias E:/server/phpmyadmin/;
try_files $uri /phpmyadmin/index.php =404;
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
I am running nginx and php from command prompt
cd `E:\server\nginx\
nginx.exe`
cd E:\server\php\
php-cgi.exe -b 127.0.0.1
server runs fine. I can access localhost/
I can also access any .php file from www folder.
PROBLEM: Problem I am facing is when I open localhost/phpmyadmin it gives me "No Input file Specified"
Please tell me I am doing wrong. Thank you in advance.
Give this an attempt:
server {
listen 80;
server_name localhost;
root E:\server\www;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /phpmyadmin {
alias E:/server/phpmyadmin/;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
}

Executing php scripts under a nginx configuration

I have the following nginx server block in its configuration
server {
listen 80;
server_name mydomain.com;
location /deploy {
alias /home/somedir/deploy/;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri =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;
}
}
I want to execute a php file at the url mydomain.com/deploy/erp/index.php or mydomain.com/deploy/erp
The above thing downloads the php file instead of executing it. I googled and found solutions that asks you to define a www directory or something. I just need to execute the file in a specific directory at specific url. What are my options?
You haven't told nginx what to do with .php files. Assuming you're using php-fpm, you'll need something like this:
server {
listen 80;
server_name mydomain.com;
root /home/somedir;
location / {
try_files $uri $uri/ =404;
}
location /deploy {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}

Categories