0
1
Добрый день уважаемые коллеги! Столкнулся с бедой и никак не могу исправить данную проблему — 502 Bad Gateway (nginx)!
И уже сутки никак не могу найти ошибку!
- Вот конфиг файла /etc/php/5.6/fpm/php-fpm.conf:
include=/etc/php/5.6/fpm/pool.d/*.conf
chroot = /var/www
chdir = /
pid = /var/run/php/php5.6-fpm.pid
error_log = /var/log/php5.6-fpm.log
- Вот конфиг файла /etc/php/5.6/fpm/pool.d/www.conf:
user = www-data
group = www-data
listen = /var/run/php/php5.6-fpm.sock
listen.owner = www-data
listen.group = www-data
- Вот конфиг файла /etc/nginx/nginx.conf:
user www-data;
worker_processes 2;
timer_resolution 100ms;
worker_rlimit_nofile 8192;
worker_priority -5;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
sendfile_max_chunk 128k;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
keepalive_requests 100;
reset_timedout_connection on;
client_body_timeout 5;
client_header_timeout 5;
send_timeout 3;
client_header_buffer_size 2k;
large_client_header_buffers 2 2k;
client_body_buffer_size 256k;
access_log off;
types_hash_max_size 2048;
server_tokens off;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/sites-enabled/*;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log crit;
charset utf-8;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_min_length 1100;
gzip_proxied any;
gzip_comp_level 4;
gzip_http_version 1.1;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
client_max_body_size 8M;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name service1.place.ru;
server_name_in_redirect off;
access_log /var/log/nginx/service.access_log;
error_log /var/log/nginx/service.error_log;
root /var/www/service1.place.ru;
fastcgi_intercept_errors on;
index index.php;
location ~ .php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5.6-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
- Все эти папки пустые:
/etc/nginx/sites-available
/etc/nginx/sites-enabled
/etc/nginx/conf.d
I have an nginx server, with php5-fpm, on Ubuntu 15.10.
files that end in «.php» load properly. HTML files load properly.
But when I put <?PHP ?>
tags in an html file, the php scripts do not load properly. I can see no errors in the nginx, or php5-fpm error logs that shed any light on the issue. view source, in the browser, lists the link to the script, rather than running the script as I would expect.
here is my nginx configuration:
#cat default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/user/public_html;
index index.php index.html index.htm;
# server_name server_domain_name_or_IP;
location / {
try_files $uri $uri/ =404;
autoindex on;
}
error_page 404 /404.html;
error_page 500 502 503 504 /404.html;
location = /404.html {
root /home/user/public_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;
}
}
the php5-fpm error log is useless:
$ sudo cat php5-fpm.log
[27-Dec-2015 07:55:13] NOTICE: error log file re-opened
the nginx error log is equaly unhelpful:
$ sudo cat nginx/error.log
2015/12/29 01:30:20 [notice] 13111#0: signal process started
(this was after I reloaded nginx)
looking at the nginx access log, it appears the php scripts inside html just never get processed. Unless called directly as in the last entry:
var/log$ sudo cat nginx/access.log
...
192.168.1.10 - - [29/Dec/2015:01:35:32 -0500] "GET /Hnav/www/scripts HTTP/1.1" 301 193 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"
192.168.1.10 - - [29/Dec/2015:01:35:32 -0500] "GET /Hnav/www/scripts/ HTTP/1.1" 200 312 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"
192.168.1.10 - - [29/Dec/2015:01:35:34 -0500] "GET /Hnav/www/scripts/sidebar.php HTTP/1.1" 200 614 "http://192.168.1.10/Hnav/www/scripts/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"
I’ve been putting up with it for a while, but I’ve had enough. I really want the <?PHP ?>
tags in html files to work, and I’m completely stuck. I can provide more detail of necessary, but Im not sure where to go from here.
I’m trying to figure out where the PHP errors are going in my setup. I’m running nginx as the reverse proxy to PHP-FPM, but I’m not seeing the various E_NOTICE or E_WARNING messages my app is producing. The only reason I know they’re happening is failed responses and NewRelic catching stack traces.
Here’s the logging config:
nginx.conf
proxy_intercept_errors on;
fastcgi_intercept_errors on;
php.ini
error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
error_log = syslog
php-fpm.conf
[global]
error_log = /var/log/php-fpm/fpm-error.log
[www]
access.log = /var/log/php-fpm/access.log
access.format = "%t "%m %r%Q%q" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_flag[log_errors] = true
rsyslog.conf
:syslogtag, contains, "php" /var/log/php-fpm/error.log
I’ve configured PHP to log to syslog, however FPM has no syslog function so it’s logging to a file. I don’t really care where the errors end up, just that they end up somewhere.
Any clues on how I might get this to work?
asked Feb 12, 2014 at 0:32
2
Your php-fpm.conf file is not set up to send errors to syslog. See below for an example of how to do this.
; 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 = syslog
; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon
; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm
; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice
answered Jul 2, 2014 at 13:52
dmuirdmuir
3114 silver badges5 bronze badges
Are you sure about your assumption for the rsyslog.conf? That is, are you sure all such syslog messages are tagged with lower-case «php»?
Try setting syslog.facility to something like local2 (or local1, or local7) and replacing your rsyslog.conf config-line accordingly:
local2.* /var/log/php-fpm/error.log
answered Apr 13, 2015 at 12:52
OtheusOtheus
4393 silver badges12 bronze badges
When you’re using php-fpm, it appears to override the php.ini
settings.
The logging most likely needs to be configured in .../www.conf
.
I uncommented these lines in order to grab the PHP logs.
php_admin_value[error_log] = /var/log/php-errors.log
php_admin_flag[log_errors] = on
The webserver user and group can also be found in this file under lines similar to this (may differ between unix socket & proxy configuration).
listen.owner = www-data
listen.group = www-data
Then it’s just a matter of creating the file and configuring it properly.
touch /var/log/php-errors.log
chmod 644 /var/log/php-errors.log
chgrp www-data /var/log/php-errors.log
chown www-data /var/log/php-errors.log
I believe the log level is still used from php-fpm.conf
so you may also need to check this.
log_level = error
answered Apr 3, 2018 at 3:33
1
Исходные данные: nginx 1.12, ubuntu 16.04, локальный сервер http с использованием вордпресс
php7.0-fpm.
В директории /etc/nginx/config.d/default.config
server {
listen 80;
server_name ~^(?:www.)?(?P<host_wo_www>.+)$;
server_name_in_redirect off;
resolver 127.0.0.1;
access_log /var/log/httpd/$host/access.log;
location ~* .(?:jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|dic|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|mp3)$
{
root /var/www/$host_wo_www/www;
access_log off;
expires 30d;
add_header Pragma public;
add_header Cache-Control public;
}
location / {
root /var/www/$host_wo_www/www;
index index.html index.htm index.php;
access_log off;
proxy_pass http://127.0.0.1:8081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
В /etc/nginx/nginx.conf
user www-data;
group www-data;
worker_processes 1;
pid /var/run/nginx.pid;
server {
location ~ .php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
}
events {
worker_connections 4096;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
client_max_body_size 100M;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
map $host $host_wo_www {
default $host;
~^www.(?P<wo_www>.+)$ $wo_www;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
</blockquote>
Cам вордпресс извлечен и хранится в /var/www/
Подключение через сокет php7.0-fpm
ИНформация по php7.0-fpm
<blockquote>tail -f /var/log/php7.0-fpm.log
[11-Feb-2016 23:33:21] NOTICE: error log file re-opened
[06-Jul-2017 21:36:10] NOTICE: Terminating ...
[06-Jul-2017 21:36:12] NOTICE: exiting, bye-bye!
[11-Feb-2016 23:28:23] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful
[11-Feb-2016 23:28:24] NOTICE: fpm is running, pid 1220
[11-Feb-2016 23:28:24] NOTICE: ready to handle connections
[11-Feb-2016 23:28:24] NOTICE: systemd monitor interval set to 10000ms
</blockquote>
<blockquote> ps aux | grep php
root 1220 0.0 1.4 140140 29756 ? Ss 12:21 0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 1223 0.0 0.3 140140 7040 ? S 12:21 0:00 php-fpm: pool www
www-data 1224 0.0 0.3 140140 7040 ? S 12:21 0:00 php-fpm: pool www
root 8169 0.0 0.0 5108 836 pts/4 R+ 13:06 0:00 grep --color=auto php
<b> # sudo systemctl restart php-fpm</b>
Failed to restart php-fpm.service: Unit php-fpm.service not found.
<b># systemctl status php7.0-fpm</b>
● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2016-02-11 23:28:24 +07; 1 years 4 months ago
Process: 1164 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS
Main PID: 1220 (php-fpm7.0)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php7.0-fpm.service
├─1220 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
├─1223 php-fpm: pool www
└─1224 php-fpm: pool www
Проблема
набираю адрес localhost/www или 127.0.0.1/www вылазит bad gateway 502
До этого сразу после установки было, что вылазила ошибка 404. Потом я добавила своего пользователя в группы root,www-data,network,local.Страница регистрации вордпресс показалась,я зарегалась. Апотом перестала открываться,снова ошибка теперь уже 502. Если ошибки обрабатываются и правильно ссылаются на каталог с хранящимися в нем страничками 404,403…,то хост работает,но почему то для моего пользователя нет.