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 *:8800>
  DocumentRoot /home/test/www
  ServerName test.domain.com


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
# 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"
# 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 "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=604800, private"
# END Cache-Control Headers

# BEGIN Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
FileETag None
# END Turn ETags Off
  • 1
    Although NGINX showing up in the server header isn't an issue, if you want to show the 'correct' server header you should be able to use proxy_pass_header Server; in your config – Smudge Aug 30 '11 at 7:13
  • @Sam: I set that up as "testserver" from the example above but it is not showing it. It is still showing the nginx server var. – lamp_scaler Aug 30 '11 at 7:40
  • 2
    proxy_pass_header passes the header through from the backend, it does not modify it. proxy_set_header (which you are using in your example) sends a header to your backend server, not the client. To change headers sent to the client you can use the more_set_headers directive of the HTTPHeadersMore module. – Smudge Aug 30 '11 at 9:07

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.

  • Thanks! I also just posted more info regarding my .htaccess file. Do I need to port some of those rules over to nginx? – lamp_scaler Aug 30 '11 at 7:34
  • @lamp_scaler if you're serving static files directly from nginx you should remove the expires and cache-control headers setup from apache and place them on nginx configuration. Same thing for text only files, you can compress and serve them directly from nginx. – Javier Constanzo Jan 21 '14 at 15:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.