2016年7月10日星期日

用nginx在Amazon EC2 AMI服务器搭建http正向代理服务

首先需要安装nginx,这里使用yum工具安装。

  • $sudo -s        //切换管理员权限
  • #yum -y install nginx        //安装nginx
  • #chkconfig --level 35 nginx on       //加入开机自动启动,可选 
  • #vi /etc/nginx/nginx.conf       //修改配置文件
找到server配置项,修改为自定义的监听端口,例:
    listen 8080 default_server;
    listen [::]:8080 default_server;
增加域名解析服务器,例:
    resolver 8.8.8.8;
在server的location项中添加:
    location / {
        proxy_pass http://$http_host$request_uri;
    }

然后保存nginx.conf文件,并启动nginx服务:
  • #/etc/init.d/nginx start
这样你就可以通过这台代理访问http服务了。

没有评论: