无法让 Apache 在装有 nginx 的服务器上运行

无法让 Apache 在装有 nginx 的服务器上运行

我被安排在办公室担任系统管理员,但我真的不知道自己在做什么。我正在运行 Ubuntu 12.04。

我们网站的服务器当前运行的是 nginx。由于大量的 php-fpm 进程不断启动,网站不断崩溃,导致一切都瘫痪。我尝试在 Google 上搜索解决方案,我修改了 nginx 配置文件,将其设置为脚本运行 10 秒后终止,但我找不到任何可以解决问题的方法。

唯一可行的解​​决方案是重新启动 php5-fpm,因此我编写了一个每 5 分钟运行一次的脚本,只是为了启动网站,这似乎有效。

我假设问题出在 nginx 和 php-fpm 上,所以我认为我只是不使用 nginx 并安装 apache(不知道这是否是一个愚蠢的解决方案)。

因此,我安装了 apache 并设置了虚拟主机。我停止了 nginx 并启动了 apache,但它没有运行。给出了错误

“无法打开日志操作‘启动’失败。Apache 错误日志可能有更多信息。”

所以我检查了日志,结果只显示“无法打开日志”,这真的帮不上什么忙。现在我不知道该怎么办了。我不知道为什么 Apache 没有运行,我实施的“修复”只是权宜之计,我需要让它正常工作。

因此,为了集中精力,当我不知道错误是什么时,我该如何排除 Apache 故障以使其运行?或者,如果有人知道为什么 php-fpm 会发疯,那也会有所帮助。


nginx配置:

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 配置文件

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 [email protected]
;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/站点可用

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;
}

答案1

您仅提供了基本的 nginx 和 apache 配置,要真正找到根本原因,我们需要 Vhost 和其他配置。由这些行指定:

包括/etc/nginx/conf.d/.conf;
包括 /etc/nginx/sites-enabled/

总的来说,这是一个非常广泛的问题。我不确定你为什么要尝试启动 Apache HTTPD,而不是修复 Nginx 和 php-fpm 实际存在的问题。但该错误听起来像是日志文件的权限错误。可能应该归 APACHE_RUN_USER 所有(如配置文件中所述)。

一般来说http://blog.chrismeller.com/configuring-and-optimizing-php-fpm-and-nginx-on-ubuntu-or-debian 是一篇关于 nginx 和 php-fpm 的好文章(不是我的)。可能有助于解决您最初的问题。祝您好运!

答案2

我认为 Apache 可能无法访问写入基本日志文件(尤其是错误日志)的目录。但有时错误消息具有误导性。

  • 检查 apache 将在哪里写入日志(应该是 /var/log/apache2)
  • 还检查 apache 是否可以写入 lock 和 pid 文件(分别应该是 /var/lock 和 /var/run)

以交互方式启动 Apache:

sudo su -
. /etc/apache2/envvars
apache2 -e DEBUG

就我而言,Apache2 报告:

[Thu Nov 28 10:19:51 2013] [debug] mod_so.c(246): loaded module alias_module
...
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

因此这个Unable to open logs信息具有误导性。

答案3

所以,问题出在已安装并正在运行的 WordPress 缓存插件上,它几乎杀死了服务器。一旦我摆脱了它,一切都正常了。谢谢。

相关内容