Nginx php-fpm subdirectory - nginx

I want to run php-fpm via nginx, but for different locations I want to specify different roots:
for path:
http://localhost/ -> /usr/share/nginx/html
http://localhost/pma -> /var/www/default/phpMyAdmin/
http://localhost/pga -> /var/www/default/phpPgAdmin/
My configuration doesn't work properly:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
try_files $uri =404;
index index.php index.html;
location / {
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /pma {
root /var/www/default/phpMyAdmin;
try_files $uri =404;
index index.html index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I always receive 404 error.

When you set location /pma and root /var/www/default/phpMyAdmin request http://server/pma/index.php was search file /var/www/default/phpMyAdmin/pma/index.php.
Use something like this:
location /pma/ {
rewrite /pma/ /phpMyAdmin/ last;
}
location /phpMyAdmin {
root /var/www/default/
try_files $uri =404;
index index.html index.php;
}
or rename /var/www/default/phpMyAdmin to /var/www/default/pma and change config to
location /pma {
root /var/www/default/
try_files $uri =404;
index index.html index.php;
}

Here is code that i'm using in nginx.
location /phpMyAdmin {
root /var/www/default;
index index.php index.html;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/default$fastcgi_script_name;
include fastcgi_params;
}
}

Related

Wordpress Permalinks - NGINX Conf (No input file specified Error)

This is my current setup for my /etc/nginx/conf.d/default.conf file on my nginx web server. I have a Wordpress installation and I am attempting to use the pretty permalinks structure like so: http://XXX.XXX.XX.X/kiosks/%postname%/
Currently getting an "No input file specified." error. Below is my default.conf:
#
# The default server
#
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
# location / {
# root /usr/share/nginx/html;
# index index.php index.html index.htm;
# }
location /kiosks {
index index.php index.html index.htm;
try_files $uri $uri/index.php?$args;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
Solution:
#
# The default server
#
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
# location / {
# root /usr/share/nginx/html;
# index index.php index.html index.htm;
# }
location #wp {
rewrite ^/kiosks(.*) /kiosks/index.php?$1;
}
location /kiosks {
alias "/usr/share/nginx/html/kiosks/"; #where wp actually is
try_files $uri $uri/ #wp;
location ~ \.php$ {
try_files $uri =404;
fastcgi_read_timeout 300s;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
# location /kiosks {
# try_files $uri $uri/index.php?$args;
# index index.php index.html index.htm;
# }
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}

nginx configuration for multiple sites one ip address and one server

nginx multiple websites on same port and one ip address
for example my ip 192.167.10.2
and we want to run site on same ip
nginx/html contain two project like below
1: project1
2: project2
we run default project1 on ip :192.167.10.2
and second project run like 192.167.10.2/project2
how do configuration in nginx config file
Here is a simple example.You could try
First config :
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/mywebsite1;
index index.php index.html index.htm;
server_name mywebsite1.de www.mywebsite1.de;
location / {
try_files $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mywebsite1;
}
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;
}
}
Second config:
server {
listen 80;
listen [::]:80 //#here Be carefull , only one default
root /var/www/mywebsite2;
index index.php index.html index.htm;
server_name mywebsite1.de www.mywebsite1.de;
location / {
try_files $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/mywebsite1;
}
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;
}
}
Don't forget to restart server.

All Laravel routes gives 404 on nginx subdirectory

I have a problem with nginx configuration. I wanna have Laravel app in subdirectory, exactly domain.com/alfa. At domain.com is another app. And now all Laravel routes gives 404 on nginx subdirectory. Could someone help find an error?
My paths:
/var/www/ <-- it's for domain.com
/var/www/alfa_path <-- it's for domain.com/alfa
It's my nginx configuration:
server
{
listen 80;
server_name domain.com;
root /var/www;
index index.php index.html index.htm;
location / {
}
location /alfa {
root /var/www/alfa_path/public;
index index.php index.html index.htm;
try_files $uri $uri/ /alfa_path/public/index.php?$query_string;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}

Laravel5 and PhpMyadmin on Digital Ocean LEMP stack

I tried to install phpMyadmin on my LEMP server using following tutorial
https://www.digitalocean.com/community/tutorials/how-to-install-phpmyadmin-on-a-lemp-server
but when I try to access myip/phpmyadmin I get page cannot be found
before this I installed laravel5 so anything i am typing after ip/anystring its being accessed by my laravel route page ,
So can you tell me how I can access the phpMyadmin
my ip is http://xxxxxxxx//phpmyadmin .
and my default page for nginx looks like this
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name xxxxxxx;
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;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Please hlp me out
Thanks
I am also stuck in the same kind of situation. Paste this code before location ~ .php$ function and it's work perfectly fine.
Source : Laravel routes overwriting phpmyadmin path with nginx
location /phpmyadmin {
root /usr/share/nginx/html;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/nginx/html;
}
}

redirect certain domain to different folders failing in nginx

I have three subdomains like m.xyz.com, test.xyz.com, prod.xyz.com, main.xyz.com. If I redirect my sub domain then it automatically locates the default folder path of the web site. I want to redirect all sub domains to different folder location. I'm using nginx server in centos, even after creating four separate .conf file it is redirecting to the default location.
.conf file code is as follows:
server {
listen 80;
server_name m.xyz.com www.m.xyz.com;
root /usr/share/nginx/html/folder1/location1/;
index index.php index.html index.htm;
location / {
#try_files $uri $uri/ =404;
try_files $uri $uri.html $uri/ #extensionless-php;
index index.html index.htm index.php;
}
# redirect server error pages to the static page /50x.html
#
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass unix:/var/run/xyz/xyz-php-fpm.sock;
fastcgi_pass 192.168.1.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# rewrites
location #extensionless-php {
rewrite ^(.*)$ $1.php last;
}
charset utf-8;
#access_log /var/log/nginx/log/host.access.log main;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

Resources