Nginx – Can’t get apache running on server with nginx

apache-2.2nginxphp-fpmUbuntu

I've been kind of thrown into the roll of sys admin at my office and don't really know what I'm doing. I'm running Ubuntu 12.04.

The server for our website is currently running nginx. The site keeps crashing because lots and lots of php-fpm processes keep starting, which is bringing down everything. I've tried googling around to find a solution, I've messed around with the nginx config file, set it so scripts die after 10 seconds of running, but nothing I've found solves the problem.

The only solution that works is to restart the php5-fpm, so I wrote a script that runs every 5 minutes that does this just to get the site up, which seems to be working.

I'm assuming the problem is with nginx and php-fpm, so I figured I'd just not use nginx and install apache(no idea if this is a dumb solution or not).

So, I installed apache and set up the virtualhost. I stop nginx and start apache, but it doesn't run. giving me an error of

"Unable to open logs
Action 'start' failed.
The Apache error log may have more information."

So I check the logs and all it says is 'Unable to open logs', which really doesn't help me. And now I don't know what to do. I don't know why Apache isn't running and the 'fix' I've implemented is just a bandaid and I need to get this working.

So, to keep this focused, how can I troubleshoot Apache to get it running, when I don't know what the error is? Or, if anyone has any ideas why php-fpm is going crazy, that would help too.


nginx config:

user www-data www-data;
worker_processes  4;
worker_rlimit_nofile 32768;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

#pcre_jit on;

events {
    worker_connections  4096;
    multi_accept on;
    accept_mutex_delay 50ms;
    use epoll;
}

http {
include       /etc/nginx/mime.types;

log_format main    '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
index index.php;
access_log  /var/log/nginx/access.log;

sendfile        on;
tcp_nopush     on;
tcp_nodelay        on;
server_tokens off;

limit_conn_zone $binary_remote_addr zone=addr:5m;

client_header_buffer_size 4k;
client_max_body_size 20M;
client_body_buffer_size 128k;
large_client_header_buffers 2 8k;

client_body_timeout 60;
client_header_timeout 60;
send_timeout        60;
keepalive_timeout  10 10;

reset_timedout_connection on;

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

gzip  on;
gzip_buffers 16 8k;
gzip_comp_level 1;
gzip_http_version 1.1;
gzip_static on;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
gzip_vary  on;
gzip_disable "msie6";
gzip_min_length 1400;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

ssl_session_cache    shared:SSL:10m;

apache.conf

LockFile ${APACHE_LOCK_DIR}/accept.lock
ServerName localhost

PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

    AccessFileName .htaccess
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy all
    </Files>


DefaultType None

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

Include ports.conf

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\""         vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

Include conf.d/
Include sites-enabled/

fpm/pool.d/www.conf

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

user = www-data
group = www-data

listen = /tmp/fpm.sock

pm = static

pm.max_children = 35
pm.start_servers = 8

pm.min_spare_servers = 1
pm.max_spare_servers = 3

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;

pm.max_requests = 500

request_terminate_timeout = 10

chdir = /

;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M

nginx/sites-available

server {
    listen [::]:80;

    server_name mydomain.com;
    return 301 $scheme://www.mydomain.com$request_uri;

}

server {
listen [::]:80;

limit_conn addr 32;

server_name www.mydomain.com;

access_log /var/www/public_html/mydomain.com/log/access.log;
error_log /var/www/public_html/mydomain.com/log/error.log;

root   /var/www/public_html/mydomain.com/public/;

## Deny access based on the User-Agent header.
if ($bad_bot) {
        return 444;
    }

location / {
    try_files $uri $uri/ @rewrites;
}

location @rewrites {
    ...
}

location ~* /\~mydomain1(.*?)$ {
    rewrite ^ /;
}

location ^~ /industry-news/ {
    rewrite ^/industry-news/?$ /news permanent;
            rewrite ^/industry-news/headlines\.rss$ /feed permanent;
    rewrite ^/industry-news/-?(.*?)(-)-?[$%]([0-9]+).*?$ /news/$1$2$3 permanent;

            try_files $uri $uri/ @rewrites;
}

location ^~ /news/ {
    ...
}

location ^~ /category/ {
            ...;
}

location ^~ /tag/ {
            ...
}

location ^~ /author/ {
    ...
}

location ^~ /tailored-news-feed {
    ...
}

location ~* contact-us\.htm$ {
    rewrite ^ /contact permanent;
}

location ~* sitemap-.*\.xml$ {
    rewrite ^ /sitemap.xml permanent;
}

location ~* \.(eot|woff|svf|ttf)$ {
    valid_referers blocked mydomain.com www.mydomain.com dev.mydomain.com;
    if ($invalid_referer) { return 444; }

    expires max;
    add_header Cache-Control public;
}

# Prevents log spam from commonly-accessed files
include global/drop.conf;

# Contains WordPress-specific restrictions & W3TC Files
include global/wordpress.conf;

    # Linkages & PHP setup
    include global/php.conf;
}
server {
    listen [::]:80;

    server_name dev.mydomain.com;

    access_log /var/www/public_html/dev.mydomain/log/access.log;
    error_log /var/www/public_html/dev.mydomain/log/error.log;

    root   /var/www/public_html/dev.mydomain/public/;

    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    # Prevents log spam from commonly-accessed files
    include global/drop.conf;

    # Linkages & PHP setup
    include global/php.conf;
}

Best Answer

You only provided the base nginx and apache config, to really get at the root cause, we'd need the Vhost and other configs. specified by these lines:

include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-enabled/
;

In General this is a VERY broad questions. I'm not sure why you're trying to get Apache HTTPD up instead of fixing the problem you actually have with Nginx and php-fpm. But that error sounds like permissions on the log file are wrong. Should probably be owned by APACHE_RUN_USER (as specified in your config file).

In general this http://blog.chrismeller.com/configuring-and-optimizing-php-fpm-and-nginx-on-ubuntu-or-debian is a good write up for nginx and php-fpm (not mine). And might help you with your original issue. Good Luck!