Linux系统(CentOS为例)
应用场景:
公司内网电脑A的访问外网网页(比如jd.com)的权限被限制,但是有一台能与电脑A通信的电脑B,这台电脑B可以访问外网,在电脑B上搭建HTTP代理,电脑A通过访问电脑B上的HTTP代理服务,即可访问jd.com。
1、 在官网下载最新稳定版本的 nginx源码
2、 默认配置编译安装 ( 需要先安装nginx所需的依赖库 )
① 依赖库安装
rpm -qa | grep zlib //查看是否安装了zlib,其他类推.
sudo yum install openssl-devel //安装openssl
sudo yum install pcre-devel //安装pcre
sudo yum install zlib-devel //安装zlib
- 1
- 2
- 3
- 4
- 5
- 6
②nginx编译
③ nginx安装
tar zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure
make
make install
3、 修改nginx运行配置文件 [ nginx 默认安装在/usr/local/nginx/下 ]
vim /usr/local/nginx/conf/nginx.conf
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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
#代理服务设置
server {
resolver 192.168.99.100; #可用的DNS
listen 81; #监听的端口
location / {
proxy_pass http://$http_host</span><span class="hljs-variable">$request_uri;
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
4、 设置nginx开机启动
vim /etc/rc.d/rc.local
在/etc/rc.d/rc.local
中添加如下代码:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- 1
5、在浏览器中设置代理IP&port即可使用
Firefox浏览器为例:“设置”–“高级”–“网络”:
nginx启动:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx停止:
/usr/local/nginx/sbin/nginx -s stop //优雅的停止nginx
/usr/local/nginx/sbin/nginx -s quit //立即停止nginxnginx重新加载配置:
/usr/local/nginx/sbin/nginx -s reload //平滑的重启nginx并重新加载nginx的配置文件;
/usr/local/nginx/sbin/nginx -s reopen //重新打开日志文件
/usr/local/nginx/sbin/nginx -t //可以用来修改配置文件之后,测试配置文件是否有语法错误
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css">
</div>