Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am setting up nginx as a reverse proxy. The server runs on directadmin and lamp stack.

I have nginx running on port 81.

I can access all my sites (including virtual ips) on the port 81. However when I forward the traffic from port 80 to 81, the virtual ips have a message saying "Apache is running normally". Server IPs are fine, and I can still access virtual IP's on 81.

   [root@~]# netstat -an | grep LISTEN | egrep ":80|:81"
tcp 0 0 <virtual ip>:81 0.0.0.0:* LISTEN
tcp 0 0 <virtual ip>:81 0.0.0.0:* LISTEN
tcp 0 0 <serverip>:81 0.0.0.0:* LISTEN
tcp 0 0 :::80 :::* LISTEN

apache 24090 0.6 1.3 29252 13612 ? S 18:34 0:00 /usr/sbin/httpd -k start -DSSL
apache 24092 0.9 2.1 39584 22056 ? S 18:34 0:00 /usr/sbin/httpd -k start -DSSL
apache 24096 0.2 1.9 35892 20256 ? S 18:34 0:00 /usr/sbin/httpd -k start -DSSL
apache 24120 0.3 1.7 35752 17840 ? S 18:34 0:00 /usr/sbin/httpd -k start -DSSL
apache 24495 0.0 1.4 30892 14756 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24496 1.0 2.1 39892 22164 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24516 1.5 3.6 55496 38040 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24519 0.1 1.2 28996 13224 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24521 2.7 4.0 58244 41984 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24522 0.0 1.2 29124 12672 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24524 0.0 1.1 28740 12364 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24535 1.1 1.7 36008 17876 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24536 0.0 1.1 28592 12084 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24537 0.0 1.1 28592 12112 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24539 0.0 0.0 0 0 ? Z 18:35 0:00 [httpd] <defunct>
apache 24540 0.0 1.1 28592 11540 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
apache 24541 0.0 1.1 28592 11548 ? S 18:35 0:00 /usr/sbin/httpd -k start -DSSL
root 24548 0.0 0.0 4132 752 pts/0 R+ 18:35 0:00 egrep apache|nginx
root 28238 0.0 0.0 19576 284 ? Ss May29 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
apache 28239 0.0 0.0 19888 804 ? S May29 0:00 nginx: worker process
apache 28240 0.0 0.0 19888 548 ? S May29 0:00 nginx: worker process
apache 28241 0.0 0.0 19736 484 ? S May29 0:00 nginx: cache manager process

here is my nginx conf:

 cat /usr/local/nginx/conf/nginx.conf
user  apache apache;

worker_processes     2; # Set it according to what your CPU have. 4 Cores = 4
worker_rlimit_nofile 8192;

pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status  $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

    server_tokens off;
    access_log  /var/log/nginx_access.log  main;
    error_log  /var/log/nginx_error.log debug;


    server_names_hash_bucket_size 64;
    sendfile on;
    tcp_nopush     on;
    tcp_nodelay    off;
    keepalive_timeout  30;
    gzip  on;
    gzip_comp_level 9;
    gzip_proxied any;

    proxy_buffering on;
    proxy_cache_path /usr/local/nginx/proxy_temp levels=1:2 keys_zone=one:15m inactive=7d max_size=1000m;
    proxy_buffer_size 16k;
    proxy_buffers 100 8k;
    proxy_connect_timeout      60;
    proxy_send_timeout         60;
    proxy_read_timeout         60;

    server {
      listen <server ip>:81 default rcvbuf=8192 sndbuf=16384 backlog=32000; # Real IP here
      server_name <server host name> _;     # "_" is for handle all hosts that are not described by server_name
      charset off;
      access_log  /var/log/nginx_host_general.access.log  main;
      location / {
        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_pass http://<server ip>;    # Real IP here
        client_max_body_size       16m;
        client_body_buffer_size    128k;
        proxy_buffering     on;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         120;
        proxy_buffer_size          16k;
        proxy_buffers              32 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
      }
  location /nginx_status {
               stub_status on;
               access_log   off;
               allow 127.0.0.1;
               deny all;
       }
    }
    include /usr/local/nginx/vhosts/*.conf;

}

here is my vhost conf:

# cat /usr/local/nginx/vhosts/1.conf
   server {
      listen <virt ip>:81 default rcvbuf=8192 sndbuf=16384 backlog=32000; # Real IP here
      server_name <virt domain name>.com ;     # "_" is for handle all hosts that are not described by server_name
      charset off;
      access_log  /var/log/nginx_host_general.access.log  main;
      location / {
        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_pass http://<virt ip>;    # Real IP here
        client_max_body_size       16m;
        client_body_buffer_size    128k;
        proxy_buffering     on;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         120;
        proxy_buffer_size          16k;
        proxy_buffers              32 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

      }
}

Apache config:

   <VirtualHost xxxxxx:80 >


        ServerName www.<domain>.com
        ServerAlias www.<domain>.com <domain>.com 
        ServerAdmin webmaster@<domain>.com
        DocumentRoot /home/<domain>/domains/<domain>.com/public_html
        ScriptAlias /cgi-bin/ /home/<domain>/domains/<domain>.com/public_html/cgi-bin/

        UseCanonicalName OFF

        <IfModule !mod_ruid2.c>
            SuexecUserGroup <domain> <domain>
        </IfModule>
        <IfModule mod_ruid2.c>


RMode config
        RUidGid <domain> <domain>
        RGroups apache access
    </IfModule>

    CustomLog /var/log/httpd/domains/<domain>.com.bytes bytes
    CustomLog /var/log/httpd/domains/<domain>.com.log combined
    ErrorLog /var/log/httpd/domains/<domain>.com.error.log



    <Directory /home/<domain>/domains/<domain>.com/public_html>
        Options +Includes -Indexes

    php_admin_flag engine ON
    php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f <domain>@<domain>.com'



</Directory>

<virtual ip address>:80       is a NameVirtualHost
         default server www.xx.com (/usr/local/directadmin/data/users/xx/httpd.conf:16)
         port 80 namevhost www.xx.com (/usr/local/directadmin/data/users/xx/httpd.conf:16)
         port 80 namevhost www.xx.co.uk (/usr/local/directadmin/data/users/xx/httpd.conf:107)
         port 80 namevhost www.xx.co.uk (/usr/local/directadmin/data/users/xx/httpd.conf:151)
         port 80 namevhost www.xx.co.uk (/usr/local/directadmin/data/users/xx/httpd.conf:195)
<virtual ip address>:443      is a NameVirtualHost
         default server www.xx.com (/usr/local/directadmin/data/users/xx/httpd.conf:61)
         port 443 namevhost www.xx.com (/usr/local/directadmin/data/users/xx/httpd.conf:61)




        <server ip>:80        is a NameVirtualHost
         default server localhost (/etc/httpd/conf/extra/httpd-vhosts.conf:29)
         port 80 namevhost localhost (/etc/httpd/conf/extra/httpd-vhosts.conf:29)
         port 80 namevhost www.xx.co.uk (/usr/local/directadmin/data/users/admin/httpd.conf:16)
share|improve this question
    
What's the Apache configuration? –  Shane Madden Jun 4 '12 at 16:36
    
added apache config. –  Sc0rian Jun 4 '12 at 16:57
    
What's configured where you've written <VirtualHost xxxxxx:80 > - an IP address or a domain name? If it's an IP, is it the exact same one as your proxy_pass http://<virt ip>; config in nginx? –  Shane Madden Jun 4 '12 at 16:58
    
<VirtualHost xxxxxx:80 > in the apache config, this is the IP address (the virtual/static ip address of this website). Yeah they are both the same IP address. –  Sc0rian Jun 4 '12 at 17:02
    
That should be right, then. What output do you get from apachectl -S? –  Shane Madden Jun 4 '12 at 17:31

1 Answer 1

up vote 0 down vote accepted

Thank you for your help Shane.

I fixed the issue. It was related to a few things.

I didn't have mod_rpaf enabled.

I used <?php print_r($_SERVER); ?> to print out the IP.

I notice the IP was wrong. Since it worked on :81, I fixed the problem by setting a destation ip in the firewall. Since I use CSF, I added it into /etc/csf.redirect. 192.168.254.62|80|10.0.0.1|81|tcp

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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