NGINX AS REV PROXY

Nginx server

[root@localhost ~]# yum install nginx

[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:1a:8c:8d brd ff:ff:ff:ff:ff:ff
inet 192.168.122.229/24 brd 192.168.122.255 scope global eth1
inet6 fe80::5054:ff:fe1a:8c8d/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# ls -l /etc/nginx/
total 80
drwxr-xr-x 2 root root 4096 Jul 14 16:17 conf.d
drwxr-xr-x 2 root root 4096 Jun 17 2015 default.d
-rw-r–r– 1 root root 979 Jun 17 2015 fastcgi.conf
-rw-r–r– 1 root root 979 Jun 17 2015 fastcgi.conf.default
-rw-r–r– 1 root root 909 Jun 17 2015 fastcgi_params
-rw-r–r– 1 root root 909 Jun 17 2015 fastcgi_params.default
-rw-r–r– 1 root root 2837 Jun 17 2015 koi-utf
-rw-r–r– 1 root root 2223 Jun 17 2015 koi-win
-rw-r–r– 1 root root 3463 Jun 17 2015 mime.types
-rw-r–r– 1 root root 3463 Jun 17 2015 mime.types.default
-rw-r–r– 1 root root 996 Jul 14 15:22 nginx.conf
-rw-r–r– 1 root root 1060 Jul 14 14:37 nginx.conf.bak
-rw-r–r– 1 root root 2685 Jun 17 2015 nginx.conf.default
-rw-r–r– 1 root root 544 Jun 17 2015 scgi_params
-rw-r–r– 1 root root 544 Jun 17 2015 scgi_params.default
drwxr-xr-x 2 root root 4096 Jul 14 15:25 sites-available
drwxr-xr-x 2 root root 4096 Jul 14 14:48 sites-enabled
-rw-r–r– 1 root root 570 Jun 17 2015 uwsgi_params
-rw-r–r– 1 root root 570 Jun 17 2015 uwsgi_params.default
-rw-r–r– 1 root root 3610 Jun 17 2015 win-utf
[root@localhost ~]# cat /etc/nginx/nginx.conf
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable “msie6”;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
open_file_cache max=10000 inactive=10m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;
ignore_invalid_headers on;
client_max_body_size 8m;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
server_names_hash_bucket_size 64;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
[root@localhost ~]# cat /etc/nginx/conf.d/linuxmadeeasy.in.conf
server {
listen 80;
server_name linuxmadeeasy.in http://www.linuxmadeeasy.in;
access_log off;
error_log /var/log/nginx/linuxmadeeasy.in-error_log crit;
location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|html|htm|wml)$ {
root /var/www/html/linuxmadeeasy.in;
expires max;
}
location / {
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_connect_timeout 30s;

proxy_redirect http://www.linuxmadeeasy.in:8080 http://www.linuxmadeeasy.in;
proxy_redirect http://linuxmadeeasy.in:8080 http://linuxmadeeasy.in;

proxy_pass https://192.168.122.22:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@localhost ~]# cat /etc/nginx/sites-enabled/linuxmadeeasy.in.conf
server {
listen 80;
server_name linuxmadeeasy.in http://www.linuxmadeeasy.in;
access_log off;
error_log /var/log/nginx/linuxmadeeasy.in-error_log crit;

location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|html|htm|wml)$ {
root /var/www/newdomain.com;
expires 30d;
}

location / {
client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_connect_timeout 30s;

proxy_redirect https://www.linuxmadeeasy.in:8080 https://www.linuxmadeeasy.in;
proxy_redirect https://linuxmadeeasy.in:8080 https://linuxmadeeasy.in;

proxy_pass https://192.168.122.22:8080/;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
————————————————–

BACK-END APACHE -SERVER
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:cb:b5:b2 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.22/24 brd 192.168.122.255 scope global eth2
inet6 fe80::5054:ff:fecb:b5b2/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# netstat -tlpn |grep 80
tcp 0 0 :::8080 :::* LISTEN 7783/httpd
tcp 0 0 :::80 :::* LISTEN 7783/httpd

[root@localhost ~]# tail -n10 /etc/httpd/conf/httpd.conf
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
Listen 8080
NameVirtualHost *:8080
DocumentRoot /var/www/html/
directoryindex linuxmadeeasy.in
ServerName linuxmadeeasy.in

[root@localhost ~]# cat /var/www/html/linuxmadeeasy.in
<head>
<body>
this will be the content from the first apache back end server
</head>
</body>
[root@localhost ~]# httpd -t
[Thu Jul 14 16:27:47 2016] [warn] NameVirtualHost *:8080 has no VirtualHosts
Syntax OK


FROM CLIENT SIDE
mohammedrafi@NOC-RAFI:~$ tail -n1 /etc/hosts
192.168.122.229 linuxmadeeasy.in

mohammedrafi@NOC-RAFI:~$ ping linuxmadeeasy.in
PING linuxmadeeasy.in (192.168.122.229) 56(84) bytes of data.
64 bytes from linuxmadeeasy.in (192.168.122.229): icmp_seq=1 ttl=64 time=0.688 ms
64 bytes from linuxmadeeasy.in (192.168.122.229): icmp_seq=2 ttl=64 time=0.672 ms
64 bytes from linuxmadeeasy.in (192.168.122.229): icmp_seq=3 ttl=64 time=0.604 ms
^C
— linuxmadeeasy.in ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.604/0.654/0.688/0.046 ms
mohammedrafi@NOC-RAFI:~$ telnet 192.168.122.229 80
Trying 192.168.122.229…
Connected to 192.168.122.229.
Escape character is ‘^]’.
GET / HTTP/1.1
HOST: linuxmadeeasy.in

HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Thu, 14 Jul 2016 10:59:21 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Last-Modified: Thu, 14 Jul 2016 10:31:56 GMT
ETag: “428d4-5d-5379602e25637”
Accept-Ranges: bytes
Content-Length: 93

<head>
<body>
this will be the content from the first apache back end server
</head>
</body>
^CConnection closed by foreign host.

Screenshot from 2016-07-14 16:31:05

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s