nginx反向代理

一、nginx反向代理和正向代理

1.nginx反向代理是将用户客服端http请求分发给内网的WEB服务器。
2.nginx正向代理是,用户客户端http可以通过nginx访问外网WEB服务器。
3.nginx的反向代理面向的是服务端,nginx的正向代理是面向的是客户端。

二、操作系统环境

宿主机系统:

root@master:~# cat /proc/version         #kali操作系统
Linux version 4.9.0-kali4-amd64 (devel@kali.org) (gcc version 6.3.0 20170415 (Debian 6.3.0-14) ) #1 SMP Debian 4.9.25-1kali1 (2017-05-04)
[root@ping ~]# cat /proc/version         #redhat操作系统
Linux version 2.6.32-573.el6.x86_64 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) ) #1 SMP Wed Jul 1 18:23:37 EDT 2015

三、配置宿主机nginx中间件

1.查看宿主机是否安装nginx

root@master:~# dpkg -l | grep nginx
ii libnginx-mod-http-auth-pam 1.13.8-1 amd64 PAM authentication module for Nginx
ii libnginx-mod-http-dav-ext 1.13.8-1 amd64 WebDAV missing commands support for Nginx
ii libnginx-mod-http-echo 1.13.8-1 amd64
……………………………………………………

四、宿主机nginx的反向代理服务

1.查看nginx的反向代理配置文件

[root@master ~]# cat /etc/nginx/conf.d/default.conf 
server {
listen 80;
server_name www.ping.cn;

access_log /var/log/nginx/host.access.log main;

location / {
proxy_pass http://192.168.100.5;
}

2.启动nginx服务

root@master:~# nginx

3.查看nginx服务的进程是否启动

root@master:~# ps -ef | grep nginx
root 5269 1188 0 13:18 ? 00:00:00 nginx: master process nginx
www-data 5270 5269 0 13:18 ? 00:00:00 nginx: worker process
www-data 5271 5269 0 13:18 ? 00:00:00 nginx: worker process
www-data 5272 5269 0 13:18 ? 00:00:00 nginx: worker process
www-data 5273 5269 0 13:18 ? 00:00:00 nginx: worker process

4.查看nginx服务的启动端口是否为80端口

root@master:~# netstat -aultnp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5269/nginx: master

五、虚拟机的WEB服务

1.查看是否安装http服务

[root@ping ~]# rpm -qa | grep httpd
httpd-2.2.15-45.el6.x86_64
httpd-tools-2.2.15-45.el6.x86_64

2.启动http服务

[root@ping ~]# /etc/init.d/httpd start

3.查看http服务是否开启

[root@ping ~]# netstat -atulnp |grep :80
tcp 0 0 :::80 :::* LISTEN 1907/httpd 

4.查看html代码文件

[root@ping ~]# ls -lh /var/www/html/
drwxr-xr-x 2 root root 4.0K 3月 7 16:05 index_files
-rw-r--r-- 1 root root 3.2K 2月 28 09:40 index.html

六、使用浏览器查看页面代码文件

1.使用浏览器访问http服务

2.使用浏览器访问nginx服务

 

posted @ 2018-03-07 16:19  瓷铜  阅读(360)  评论(0编辑  收藏  举报