Ubuntu 16.04, nginx, phpmyadmin - 502 Bad Gateway - php

I am using this setting for nginx (default file):
server {
listen 30425;
# Don't want to log accesses.
#access_log /dev/null main;
access_log /var/log/nginx/php.acces_log main;
error_log /var/log/nginx/php.error_log info;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
error_page 401 403 404 /404.php;
location ~ .*.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}
When I try to access 30425, I am getting 502 Bad Gateway. All other setting are default one (PHP 7).

I had to replace this fastcgi_pass 127.0.0.1:9000;
to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
and then it worked perfectly.
Full code.
server{
listen 80;
index index.html index.htm index.php;
server_name 127.0.0.1;
root /usr/share/phpmyadmin;
location / {
#try_files $uri $uri/ = 404;
autoindex on;
}
location ~\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+);
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_na$
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}

Related

Nginx: location for subfolder

I want to move my root project to subfolder.
My current config is:
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
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;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
And current project structure as expected:
/var/www/public
﹂index.php
The problem is to rewrite locations ~ \.php$ and / with new variable of subfolder (project name).
/var/www/new-project/public
﹂index.php
I've tried to rewrite locations but it didn't work:
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
# root /var/www/public;
root /var/www;
location ~ ([a-zA-Z0-9_\/\.]+)\.php$ {
try_files $uri =404;
fastcgi_split_path_info ^$1(.+\.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;
}
location ~/([a-zA-Z0-9_\/\.]+)$ {
alias /var/www/$1/public;
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
I think second location is pretty valid but I can't get how to rewrite it for \.php$ ending.
Found some overcome for this problem:
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/;
location / {
deny all;
return 404;
}
location ~ /([a-zA-Z0-9-_]+)/(.+\.php$) {
alias /var/www/$1/public/$2;
# try_files $uri =404;
fastcgi_split_path_info ^/$1/(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/$1/public/$2/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /([a-zA-Z0-9-_]+)/$ {
alias /var/www/$1/public/;
# try_files $uri $uri/ /index.php?$query_string;s
gzip_static on;
}
}
But the only one disadvantage of this approach that you can not use try_files with the alias.

Nginx change the root location to wordpress site

Currently I have a Wordpress site under /var/www/html/wordpress and other php projects under /var/www/html/projects. I want my root location to point to wordpress one. Here is my current nginx config:
server {
listen 80 default_server;
server_name _;
set $yii_bootstrap "index.php";
root /var/www/html;
client_max_body_size 2M;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /projects/inspection/ {
root /var/www/html;
try_files $uri /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
location /projects/ {
root /var/www/html;
index index.html $yii_bootstrap;
try_files $uri $uri/ /$yii_bootstrap?$args /index.php$is_args$args;
}
location / {
root /var/www/html/wordpress;
try_files $uri $uri/ =404;
index index.php index.html index.htm;
}
location ~ \.php{
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
}
But it returns 404. I tried to put alias instead and it returns 403 forbidden. How should I handle this?

Nginx index module not point to index.php

My problem is access main site: example.com not point to index.php, i have to manually enter full url example.com/index.php.
Subdomain sub01.example.com working well, automatic point to index.php.
I've 3 site as bellow, please help to check
main site: example.com
subdomain: sub01.example.com, sub02.example.com
and this is my configure:
server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
# root directive should be global
root /var/www/example.com/;
index index.php;
access_log /var/www/example.com/logs/nginx_access.log;
error_log /var/www/example.com/logs/nginx_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
server {
listen 80;
server_name sub01.example.com www.sub01.example.com;
# root directive should be global
root /var/www/sub01.example.com/;
index index.php;
access_log /var/www/sub01.example.com/nginx_access.log;
error_log /var/www/sub01.example.com/nginx_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
server {
listen 80;
server_name sub02.example.com www.sub02.example.com;
# root directive should be global
root /var/www/sub02.example.com/;
index index.php;
access_log /var/www/sub02.example.com/logs/nginx_access.log;
error_log /var/www/sub02.example.com/logs/nginx_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
I'm sorry.
This configuration was fine.
Error come from cloudflare DNS pointer config.

Nginx on vagrant not loaded assets for symfony2

I have problem with my website, all assets(css,js,fonts) not loaded.
My configuration :
server {
listen 80;
server_name shop.dev;
index index.php index.html index.htm;
access_log /var/log/nginx/test.dev.access.log;
error_log /var/log/nginx/test.dev.error.log;
location / {
#index app_dev.php;
#try_files $uri /app_dev.php?$args;
try_files $uri /app_dev.php$is_args$args;
}
location ~ .php$ {
root /home/vagrant/Workspace/shop/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
I use vagrant machine. Exist a solution? Help me please!!

The php file is download instead execute on nginx

I use the Symfony config of Nginx server:
server {
server_name cmf.localhost www.cmf.localhost;
root /mnt/hgfs/www/cmf/web;
error_log /var/log/nginx/cmf.error.log;
access_log /var/log/nginx/cmf.access.log;
# strip app.php/ prefix if it is present
rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;
location = /libs/ckfinder/core/connector/php/connector.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
location / {
index app_dev.php app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
and it work well, but I also need to execute /libs/ckfinder/core/connector/php/connector.php. Now when I try to execute them, it simply download.
How can I config Nginx to executed /libs/ckfinder/core/connector/php/connector.php file?
server {
listen 80;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
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;
}
}

Categories