3

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
3
  • 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
    – user80776
    Aug 30, 2011 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. Aug 30, 2011 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.
    – user80776
    Aug 30, 2011 at 9:07

1 Answer 1

4

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.

2
  • Thanks! I also just posted more info regarding my .htaccess file. Do I need to port some of those rules over to nginx? Aug 30, 2011 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. Jan 21, 2014 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .