本文操作环境 centOS 7
一、通过yum安装
1,将nginx添加到yum repro库中
[root@izbp1b498epn4trb75oykez ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2,查看nginx信息
[root@cwtp1b498epn4trb75oykms ~]# yum info nginx
3,使用yum安装ngnix
[root@cwtp1b498epn52rb75oykms ~]# yum -y install nginx
4,启动nginx
[root@cwtp1b498epn4trb75oykms ~]# systemctl start nginx
二、nginx配置
- 如果你是和我一步步操作下来,那么你的nginx配置文件地址应该和我是一样的
[root@cwtp1b498epn52rb75oykms ~]# vi /etc/nginx/conf.d/default.conf
添加一个新的server,这个配置主要是将监听80端口,将来自blog.csdn.net的请求转发到本地4355端口
server {
listen 80;
server_name blog.csdn.net;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://127.0.0.1:4355;
}
}
- 配置完成保存退出,然后重启nginx,使配置生效
[root@cwtp1b498epn52rb75oykms conf.d]# systemctl reload nginx.service