
安装 Nginx
sudo apt-get install nginx
//中间要输入 y 确认
nginx -v //查看 nginx 版本,确认安装成功

添加配置文件
cd /etc/nginx/conf.d //进入配置文件的目录
sudo vi chengong-shop-8888.conf
//新增配置文件,这里的命名习惯是把域名、端口号作为配置文件名,一目了然
添加配置参数
upstream chengong {
server 127.0.0.1:8888;
}
server {
listen 80;
server_name 47.94.198.140;
location / {
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://chengong;
proxy_redirect off;
}
}
测试 nginx
配置文件
sudo nginx -t
测试成功

重启 nginx
服务
sudo nginx -s reload
验收成果
在浏览器输入 ip 地址 47.94.198.140
发现可以访问,不需要通过 8888 端口了,可以通过默认的 80 端口访问。

查看 network 的服务器返回的 Headers

可以看到 nginx
的版本信息为 1.4.6(Ubuntu),我们想把版本信息隐藏怎么做呢?
隐藏 Response Headers 里的 nginx
版本信息
sudo vi /etc/nginx/nginx.conf
//去掉注释,文件里的 server_tokens off,


重启 nginx
服务
sudo service nginx reload
现在我们再去看 Response Headers 里的 nginx
版本信息,可以发现,版本信息隐藏了

总结:通过 nginx
反向代理,可以隐藏端口号,通过默认的 80 端口访问。修改 nginx
配置隐藏了 Response Headers 里的版本信息 ,接下来下一章我们就把这串数字 ip 更换成购买的域名
网友评论