nginx problem accessing virtual hosts
Posted
by
Sc0rian
on Pro Webmasters
See other posts from Pro Webmasters
or by Sc0rian
Published on 2012-06-04T09:47:13Z
Indexed on
2012/06/04
10:51 UTC
Read the original article
Hit count: 489
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;
}
}
© Pro Webmasters or respective owner