Linux – Potential problems with using Nginx and Apache on the same server

apache-2.2centoslinuxnginxweb-server

I installed nginx to handle requests alongside apache. Before, apache listened on port 80 and I've now switched to nginx to listen on port 80 and apache on some obscure port and have nginx proxy_pass to apache if the request is for non-static content.

My nginx config contains the following:

server {
    listen 80;
    server_name static.test.domain.com;
    location / {
        root   /home/test/www/static;
        index  index.html index.htm;
    }

}

server {
    listen       80;
    server_name domain.com *.domain.com;
    location /
    {
        proxy_set_header Server "testserver";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8800;

    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

The apache vhost config has the following:

NameVirtualHost *:8800

<VirtualHost *:8800>
  DocumentRoot /var/www/html
  ServerName domain.com
  ServerAlias www.domain.com
</VirtualHost>

<VirtualHost *:8800>
  DocumentRoot /home/test/www
  ServerName test.domain.com
</VirtualHost>

...

I've noticed that the requests are faster now but I've also noticed that nginx is showing up at all the request header in the Server field, even if the request is for non-static pages. Is this a potential problem? I've seen some servers that use nginx on the same IP like my setup but the Server field is different (Apache shows up if it is a non-static content request, nginx show up when static).

Additionally, I'm using APC for opcode caching and I'm using .htaccess with a few redirect rules within my site directory (I'm thinking I need to port some apache rules over to nginx? Is that necessary?). I also have a few Java cron scripts that run (will this impede the nginx process?) Can this new setup lead to potential problems?

Lot's of questions, I know. But thanks in advance!

More info: using nginx 1.0.6 with apache 2.2 running on Centos 5 32bit.

My .htaccess file (does some of this need to be ported over to apache?):

# BEGIN Compress text files
<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>
# END Compress text files


# BEGIN Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 604800 seconds"
  ExpiresByType application/javascript "access plus 604800 seconds"
  ExpiresByType application/x-javascript "access plus 604800 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers


# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=604800, private"
  </filesMatch>
</ifModule>
# END Cache-Control Headers


# BEGIN Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off

Best Answer

Consider installing mod_rpaf for Apache, this will help you to get IP addresses of clients in Apache access logs, not IP address of your server (technically, nginx requests web pages from Apache so Apache recognises its IP as a client IP without mod_rpaf). This is the only possible problem with your setup I can think of, everything else looks correct. It is correct to have nginx in every header since nginx works as a frontend to every web page, both static and dynamic.