facing issue with nginx.conf for my php application - php

I am trying to configure http server for my php application in nginx but getting this error when i tring to start the service if someone can help it would be really great.
follow error i am getting when i use command to start the service
-- Subject: Unit nginx-rtmp.service has begun reloading its configuration
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit nginx-rtmp.service has begun reloading its configuration
Nov 22 15:54:43 chandu nginx[19339]: nginx: [emerg] pattern "^(.+\.php)(/.*)chr(36)" must have 2 captures in /opt/nginx-rtmp/conf/nginx.conf:38
Nov 22 15:54:43 chandu systemd[1]: nginx-rtmp.service: Control process exited, code=exited status=1
Nov 22 15:54:43 chandu systemd[1]: Reload failed for Nginx RTMP.
-- Subject: Unit nginx-rtmp.service has finished reloading its configuration
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit nginx-rtmp.service has finished reloading its configuration
--
-- The result is failed.
lines 1256-1284/1284 (END)
My nginx.conf file
following is my nginx.conf file fastcgi_split_path_info ^(.+.php)(/.*)chr(36); is at line 38 where error points to above.
user nginx;
worker_processes 2;
pid /run/nginx-rtmp.pid;
error_log logs/error.log;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
}
}
http {
access_log logs/access.log;
include mime.types;
server {
listen 26765;
location /stat {
rtmp_stat all;
}
}
server {
listen 80;
root /opt/panel/public;
location / {
try_files chr(36)uri /index.phpchr(36)is_argschr(36)args;
}
location ~ ^/index\.php(/|chr(36)) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)chr(36);
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME chr(36)realpath_rootchr(36)fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT chr(36)realpath_root;
internal;
}
location ~ \.phpchr(36) {
return 404;
}
}
}
nginx-rtmp.service file
this is my service that is created to start nginx server
[Unit]
Description=Nginx RTMP
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx-rtmp.pid
ExecStartPre=/opt/nginx-rtmp/sbin/nginx -t
ExecStart=/opt/nginx-rtmp/sbin/nginx
ExecReload=/opt/nginx-rtmp/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Updated nginx.config service started but getting 502 bad gateway error upon opening application on browser
user nginx;
worker_processes 2;
pid /run/nginx-rtmp.pid;
error_log logs/error.log;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
}
}
http {
access_log logs/access.log;
include mime.types;
server {
listen 26765;
location /stat {
rtmp_stat all;
}
}
server {
listen 80;
root /opt/panel/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
}
}
php-fpm.conf data
[global]
pid = /www/server/php/74/var/run/php-fpm.pid
error_log = /www/server/php/74/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi-74.sock
listen.backlog = 8192
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_74_status
pm.max_children = 150
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
request_terminate_timeout = 100
request_slowlog_timeout = 30
slowlog = var/log/slow.log

Related

What should I check from nginx & php-fpm / FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream

As I know, when I meet "File not fount" error from Nginx & php-fpm server,
I have to check the each process's owner:group.
Look below.
the owner for php-fpm process is 'nginx'
and
the owner for nginx process is 'nginx'
and
the owner of the file www.sock is 'nginx' too.
But my website has 'file not found' error yet.
What should I check another?
-------- nginx conf -------
root /home/gotoabc/pixel/www;
...
location ~* \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
...
------ /etc/php-fpm-7.2.d/www.conf ---------
user = nginx
group = hosting
...
listen = /var/run/php-fpm/www.sock
...
listen.owner = nginx
listen.group = hosting
listen.mode = 0660
-------- /home/gotoabc/pixel/www ---------
-rwxr-xr-x 1 gotoabc hosting 5878 Dec 11 03:09 index.php

Nginx, PHP - An error occurred. Sorry, the page you are looking for is currently unavailable. Please try again later

I get an error when I access my index.php of my /usr/local/nginx-1.12.2/html.
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
Faithfully yours, nginx.
My nginx.conf is this:
# cat conf/nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
}
in my /usr/local/php-7.1.16/etc, the php-fpm.conf config is this:
# cat php-fpm.conf
[global]
pid = /usr/local/php-7.1.16/var/run/php-fpm.pid
error_log = /usr/local/php-7.1.16/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 60
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 60
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
My php-fpm is running. I can use ps -ef | grep php-fpm to check. there are multi processes at there.
my index.php is just a phpinfo():
index.php:
<?php
ini_set("display_errors","On");
error_reporting(E_ALL);
echo phpinfo();
?>
EDIT-1
In my nginx's error.log:
2018/06/25 09:36:02 [error] 12360#0: *13338 connect() failed (111: Connection refused) while connecting to upstream, client: 118.113.137.192, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "101.103.23.5"
EDIT-2
Thanks Dan, I changed the fastcgi_pass 127.0.0.1:9000 to:
fastcgi_pass unix:/tmp/php-cgi.sock;
But I get the File not found. error, when I access the index.php.
You specify a unix socket for fpm to listen:
listen = /tmp/php-cgi.sock
But in nginx you specify an IP address:
fastcgi_pass 127.0.0.1:9000;
Configure either IP only or Unix Socket only:
fastcgi_pass unix:/tmp/php-cgi.sock;
or
listen = 127.0.0.1:9000
Concerning your edit 2:
Try adding this param:
fastcgi_split_path_info ^(.+\.php)(/.+)$;
And also your SCRIPT_FILENAME does not look correct, the folder you specify most probably does not exist (/scripts).
Try this dynamic path:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
You should use the bellow configurations of php in nginx:
location ~ \.php$ {
root html;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
The $document_root$fastcgi_script_name statement is invalid now.

502 Bad Gateway Nginx after server restore

So I've got a Ubuntu server that I'm trying to restore from a backup. And when a dummy PHP version page I get 502 Bad Gateway. What have I tried to fix it? Quite a few things including the answers from this related question - nginx 502 bad gateway
This is my default config with Ubuntu
server {
listen 80;
# listen [::]:81 ipv6only=on default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name localhost;
location ~* \.(js|css|png|jpg|jpeg|gif|ico|html)$ {
expires max;
}
location / {
try_files $uri $uri.php $uri.php/$args /index.php?q=$uri&$args $uri/ =404;
index index.php index.html index.htm;
rewrite ^(.*)$ /$1.php;
}
location /phpmyadmin {
index index.php;
try_files $uri $uri/ =404;
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
}
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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
EDIT:
Here's what I think is the relevant part of the log
2017/08/11 13:18:13 [error] 27759#0: *270 connect() failed (111: Connection refused) while connecting to upstream, client: 66.61.18.112, server: domain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "[IP ADDRESS]", referrer: "http://[IP ADDRESS]/phpmyadmin/index.php"
EDIT 2:
Here's the result when I run ps aux | grep php-fpm:
mre 21685 0.0 0.0 11756 932 pts/0 S+ 10:42 0:00 grep --color=auto php-fpm
root 32721 0.0 1.0 269300 11168 ? Ss Aug11 0:30 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 32724 0.0 0.4 269300 4540 ? S Aug11 0:00 php-fpm: pool www
www-data 32725 0.0 0.4 269300 4540 ? S Aug11 0:00 php-fpm: pool www
Edit 3:
Here's what's uncommented out of my php-fpm.conf
[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /var/run/php5-fpm.pid
; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php5-fpm.log
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf
Edit 4:
Here's what's uncommented from my www.conf:
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
Edit 5:
My nginx log after I try to go to index.php:
[error] 29393#0: *23 connect() failed (111: Connection refused) while connecting to upstream, client: [Computer IP Address], server: [Subdomain.domain.com], request: "GET /favicon.ico HTTP/1.1", upstream:"http://127.0.0.1:8080/favicon.ico", host: [Server IP], referrer: "http://[Server IP]/index.php"
So I checked out my nginx config and found these lines:
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
Then I went to /etc/nginx/conf.d/*.conf and saw that in the servers.conf file, there was a config for a sub domain that I planned on using but won't anymore so I deleted it. This was a big part of the problem because nginx was looking in this config first and that's why the errors included this subdomain.
As for the php problems, I switched my config to fastcgi_pass unix:/run/php/php7.0-fpm.sock; and that seems to have fixed the problem.
Try to replace
fastcgi_pass unix:/var/run/php5-fpm.sock;
in your nginx config to
fastcgi_pass 127.0.0.1:9000;
Because if your PHP-FPM config you use TCP instead of socket (it's OK).
You have to change this line
from:
listen = 127.0.0.1:9000
to:
listen = /var/run/php5-fpm.sock
in your www.conf file
Don't forget to restart php.
Explanation:
If you look at your nginx virtual host fastcgi_pass parameter
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;
}
you'll see that you are pointing processing of php files to php5-fpm socket but in your www.conf file php is listening port 9000 which is why you should change it to /var/run/php5-fpm.sock

nginx: [emerg] could not build referer_hash, you should increase referer_hash_bucket_size: 64

Good Day,
I am a novice to php and i am trying to run the livehelperchat open source code(https://livehelperchat.com/) in my ubuntu-16.04 instance and I have Nginx as default server listening port 80 and also php 5.6 running.
/var/www/html/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name xxxxxxxxx;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5.6-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I can visit php info page in my web browser by visiting my server's domain name or public IP address followed by /info.php
I have my code at /var/www/html/livehelperchat/
I have fallowed the below link to set up the project in nginx
https://livehelperchat.com/nginx-configuration-tips-132a.html
/var/www/html/sites-enabled/example.conf
server {
listen 80;
server_name xxxxxxxxxxxxxxxxxxxxxxxxxxx;
root /var/www/html/livehelperchat;
location ~* (^(?!(?:(?!(php)).)*/(albums|bin|var|lib|cache|doc|settings|pos|modules)/).*?(index\.php|upgrade\.php)$) {
include /etc/nginx/livehelperchat_fastcgi_params;
fastcgi_pass unix:/var/run/php5.6-fpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $query_string;
# fastcgi_param SCRIPT_FILENAME /var/livehelperchat/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
#Allow hotlinking to normal and thumb size images
location ~* (normal_|thumb_|^/design|^/cache|^/var/storagetheme)(.*)\.(gif|jpe?g?|png|mp3|svg|otf|woff|eot|ttf|ogg|wav|bmp|htm|swf|css|js|swf|pdf|ico)$ {
## #todo: add expires headers...
# favicon is only stored in 1 dir, the design one; But browsers ask for it in the root
if ($http_user_agent ~* "(WebReaper|wget|SiteSucker|SuperBot|Mihov Picture Downloader|TALWinHttpClient|A1 Website Download|WebCopier|Download Ninja|Microsoft URL Control|GetRight|Arachmo|MJ12bot|Gaisbot|Anonymous|Yanga|Twiceler|psbot|Irvine|Indy Library|HTTrack)" ) {
return 403;
}
if ($http_referer ~* (stockingteensex.info|cbox.ws|teensos.net|dpstream.net|tagged.com|kaskus.us|gorilladatingservice.info|taringa.net|discuss.com|craigslist.org|poringa.net)) {
return 403;
}
#sendfile off;
#aio on;
directio 512;
expires max;
access_log off;
root /var/www/html/livehelperchat;
}
# Do not allow to hotlink full size images except our self and major search engines
location ~* \.(gif|jpe?g?|png|bmp|swf|css|js|svg|otf|eot|ttf|woff|swf|mp3|ogg|wav|pdf|ico|txt)$ {
## #todo: add expires headers...
valid_referers none blocked server_names ~(livehelperchat.com|google.|reddit.|bing.|yahoo.);
if ($invalid_referer) {
return 403;
}
if ($http_user_agent ~* "(WebReaper|wget|SiteSucker|SuperBot|Mihov Picture Downloader|TALWinHttpClient|A1 Website Download|WebCopier|Download Ninja|Microsoft URL Control|GetRight|Arachmo|MJ12bot|Gaisbot|Anonymous|Yanga|Twiceler|psbot|Irvine|Indy Library|HTTrack)" ) {
return 403;
}
if ($http_referer ~* (stockingteensex.info|cbox.ws|teensos.net|dpstream.net|tagged.com|kaskus.us|gorilladatingservice.info|taringa.net|discuss.com|craigslist.org|poringa.net)) {
return 403;
}
#sendfile off;
#aio on;
directio 512;
expires max;
root /var/www/html/livehelperchat;
}
location / {
rewrite "^(.*)$" "/index.php?$1" last;
}
}
Now I am getting an error on doing nginx -t
nginx: [emerg] could not build referer_hash, you should increase referer_hash_bucket_size: 64
nginx: configuration file /etc/nginx/nginx.conf test failed
service nginx restart
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
systemctl status nginx.service
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2017-04-22 10:15:40 UTC; 1min 14s ago
Process: 24237 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
Process: 24232 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry TERM/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCES
Process: 24111 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 31591 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 24134 (code=exited, status=0/SUCCESS)
Apr 22 10:15:40 ip-172-31-28-209 systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 22 10:15:40 ip-172-31-28-209 nginx[31591]: nginx: [emerg] could not build referer_hash, you should increase referer_hash_bucket_si
Apr 22 10:15:40 ip-172-31-28-209 nginx[31591]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 22 10:15:40 ip-172-31-28-209 systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 22 10:15:40 ip-172-31-28-209 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 22 10:15:40 ip-172-31-28-209 systemd[1]: nginx.service: Unit entered failed state.
Apr 22 10:15:40 ip-172-31-28-209 systemd[1]: nginx.service: Failed with result 'exit-code'.
Any Help is Highly Appreciated. Thanks in Advance
Must be a bug of Plesk, there is no way anymore to change the values also as the support told me.
I need to reinstall the server.

Nginx error FastCGI sent in stderr: "Access to the script [folder] has been denied (see security.limit_extensions)"

I am trying to configure my webserver using Nginx and php-fpm
I have successfully configured before in my local computer and dev server, but not now in AWS.
The only difference is I installed Nginx from a source in production server
It gives an error like these in my /var/log/nginx/error.log
2014/03/11 11:09:19 [error] 11138#0: *1 FastCGI sent in stderr: "Access to the script '/home/ambassador-portal/ambassador-api/web' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 202.62.16.225, server: brandapi.whatiwear.com, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "brandapi.whatiwear.com", referrer: "http://brandapi.whatiwear.com/"
While the error log in php-fpm gives no error
Here is my nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include /usr/local/nginx/conf/sites-enabled/*.conf;
}
Here is my nginx_host.conf
server {
server_name brandapi.whatiwear.com;
access_log /var/log/nginx/brandapi_access.log;
error_log /var/log/nginx/brandapi_error.log;
root /home/ambassador-portal/ambassador-api/web;
disable_symlinks off;
autoindex on;
location / {
try_files $uri $uri/ /app.php$uri?$args;
}
location ~ \.htaccess {
deny all;
}
location ~ \.php$ {
fastcgi_split_path_info ^((?U).+\.php)(.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include /usr/local/nginx/conf/fastcgi_params;
}
}
Here is my /etc/php5/fpm/conf/www.conf
; Start a new pool named 'www'.
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = ec2-user
group = ec2-user
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
security.limit_extensions = .php .php3 .php4 .php5 .html .htm
php_admin_value[error_log] = /var/log/php-fpm/5.5/www-error.log
php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 128M
; Set session path to a directory owned by process user
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/5.5/session
I've read from access denied on nginx and php and try to chmod and I've tried the solution from Nginx 403 forbidden for all files and here is my result
dr-xr-xr-x root root /
drwxr-xr-x root root home
drwxr-xr-x ec2-user ec2-user ambassador-portal
drwxr-xr-x ec2-user ec2-user ambassador-api
drwxr-xr-x ec2-user ec2-user web
I turned the autoindex on just for seeing if my root directory is right, the weird thing is I can open all files except PHP files
You can see a live example at http://brandapi.whatiwear.com/
What is wrong with my webserver..?
I removed these two configurations from the nginx.conf file.
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
It works.
The problem is in this line
(in your /etc/php5/fpm/conf/www.conf)
security.limit_extensions = .php .php3 .php4 .php5 .html .htm
Just add the extension .pl after .htm.
Cheers.

Categories