Nginx 反向代理导致 apache2 关闭

Nginx 反向代理导致 apache2 关闭

我有一个运行反向代理 apache2 服务器的 nginx 服务器。当我通过 localhost:8001(即直接通过 apache2 服务器)访问页面时,每个页面都可以正常加载。而当我通过 nginx 加载页面时,我收到以下错误:

AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

尤其是以下页面:http://localhost/series/adventure/adult/helloworld2会引发此错误。我感觉 .htaccess 中有一个规则与 nginx 的配置循环。但我不知道是哪一个。apache2 抛出上述错误后,无法再访问任何页面。

version: "2"
services:
    nginx: 
        image: nginx:latest
        volumes:
            - ./config/nginx.conf:/etc/nginx/nginx.conf:delegated
        ports:
            - 80:80
        depends_on:
            - www
        networks:
            - default
    www:
        build: .
        volumes:
            - ./www:/var/www/html/:delegated
            - ./config/php.ini:/usr/local/etc/php/php.ini:delegated
        ports:
            - 8001:80
        networks:
            - default

以及以下 nginx.conf

events{}
http {
    upstream www {
        server www:80;
    }
    server {
        listen 80;
        server_name localhost;

        location / {
            proxy_pass http://www/;
            proxy_connect_timeout 159s;
            proxy_send_timeout   600;
            proxy_read_timeout   600;
            proxy_buffer_size    64k;
            proxy_buffers     16 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
}

以及以下 .htaccess 文件

<IfModule mod_rewrite.c>


<IfModule mod_env.c>
  SetEnv HTTP_MOD_REWRITE On
  </IfModule>

  RewriteEngine on

  #REDIRE HTTPS
  #RewriteCond %{HTTPS} off
  #RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
  #REDIR WWW
  #RewriteCond %{HTTP_HOST} !^www\.
  #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA]

  #resize photos
  RewriteRule ^photos_(\d*?)x(\d*?)\/(.*)(.jpg|.jpeg|.png|.gif)$ %{ENV:REWRITEBASE}/lib/timthumb/timthumb.php?src=/photos/$3$4&w=$1&h=$2&zc=1 [NC,L]

  #RewriteRule ^photos_ext_(\d*?)x(\d*?)\/http([s]*).*?\/(.*)(.jpg|.jpeg|.png|.gif)$ %{ENV:REWRITEBASE}/lib/timthumb/timthumb.php?src=http$3://$4$5&w=$1&h=$2&zc=1 [NC,L]
  #RewriteRule ^photos_ext_(\d*?)\/http([s]*).*?\/(.*)(.jpg|.jpeg|.png|.gif)$ %{ENV:REWRITEBASE}/lib/timthumb/timthumb.php?src=http$2://$3$4&w=$1&h=$2&zc=1 [NC,L]

  RewriteRule ^photos_(\d*?)\/(.*)(.jpg|.jpeg|.png|.gif)$ %{ENV:REWRITEBASE}/lib/timthumb/timthumb.php?src=/photos/$2$3&w=$1&h=$1&zc=1 [NC,L]
  RewriteRule ^visuels_(\d*?)\/(.*)(.jpg|.jpeg|.png|.gif)$ %{ENV:REWRITEBASE}/lib/timthumb/timthumb.php?src=/visuels/$2$3&w=$1&h=$1&zc=1 [NC,L]


  #js traductions
  RewriteRule ^themes\/.*?\/js\/traduction.js$ %{ENV:REWRITEBASE}/traductionjs [NC,L,R=301]


  # Dispatcher
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -s [OR]
  RewriteCond %{REQUEST_FILENAME} -l [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [NC,L]
  RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>


<IfModule mod_php5.c>
  php_value short_open_tag 1
</IfModule>

#<FilesMatch "\.(js)$">
#Header set Access-Control-Allow-Origin "*"
#</FilesMatch>


#optimisations
Options -Indexes
ServerSignature Off
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype image/svg+xml application/x-httpd-php
#Pour les navigateurs incompatibles
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
#les proxies doivent donner le bon contenu
Header append Vary User-Agent env=!dont-vary

<IfModule mod_headers.c>
  Header always set X-FRAME-OPTIONS "SAMEORIGIN"
  Header always set X-XSS-Protection "1; mode=block"
  Header always set X-Content-Type-Options "nosniff"
</IfModule>


<ifModule mod_php5.c>
  php_value zlib.output_compression 16386
  php_value zlib.output_compression_level 5
</ifModule>


FileETag none
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"

ExpiresByType text/css "access plus 0 seconds"
ExpiresByType text/javascript "access plus 0 seconds"
ExpiresByType application/x-javascript "access plus 0 seconds"
</IfModule>



#No cache for DEV mode
<filesMatch "\.(js|css)$">
  FileETag None
  <ifModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>

答案1

我在另一个帖子中看到,nginx 不需要反向代理 apache2,因为 apache2 已经内置了该功能。

我最终做的是使用 apache2 作为反向代理/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:*>
ProxyPreserveHost On

# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example: 
ProxyPass / http://www/
ProxyPassReverse / http://www/

ServerName localhost
</VirtualHost>

相关内容