Nadya19962017-07-07 10:40:21
Nadya1996, 2017-07-07 10:40:21

502 Bad Gataweway, nginx 1.12 ubuntu 16.04. What's wrong again?

Initial data: nginx 1.12, ubuntu 16.04, local http server using
wordpress php7.0-fpm.
In /etc/nginx/config.d/default.config directory

server {
  listen 80;
  server_name ~^(?:www\.)?(?P<host_wo_www>.+)$;
  server_name_in_redirect	off;

  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_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

In /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/*;
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> 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

The problem
is I type the address localhost / www or / www climbs out bad gateway 502
Before that, immediately after installation, it was that I got a 404 error. Then I added my user to the root, www-data, network, local groups. The WordPress registration page appeared, I've signed up. Apotom stopped opening, again the error is now 502. If the errors are processed and correctly refer to the directory with 404,403 pages stored in it ..., then the host works, but for some reason it doesn’t for my user.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Dmitry, 2017-09-05

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

in fpm config

Dmitry, 2017-07-14

If you are just starting to deal with setting up a web server, it is best to follow the most simple and closest to the original manuals.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question