【centos安装部署】安装nginx

一、安装gcc gcc-c++
yum install -y gcc gcc-c++

二、下载tar.gz包
下载地址http://nginx.org/en/download.html

三、安装
#根目录使用ls命令可以看到下载的nginx压缩包,然后解压
tar -zxvf nginx-1.16.1.tar.gz

#解压后进入目录
cd nginx-1.16.1

#使用默认配置
./configure

#编译安装
make
make install

#查找安装路径,默认都是这个路径
[root@VM_0_12_centos ~]# whereis nginx
nginx: /usr/local/nginx

#启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx #启动
./nginx -s stop #停止,直接查找nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit #退出停止,等待nginx进程处理完任务再进行停止
./nginx -s reload #重新加载配置文件,修改nginx.conf后使用该命令,新配置即可生效

#重启nginx,建议先停止,再启动
./nginx -s stop
./nginx

#查看nginx进程,如下返回,即为成功
[root@VM_0_12_centos ~]# ps aux|grep nginx
root 5984 0.0 0.0 112708 976 pts/1 R+ 14:41 0:00 grep --color=auto nginx
root 18198 0.0 0.0 20552 612 ? Ss 11:28 0:00 nginx: master process ./nginx
nobody 18199 0.0 0.0 23088 1632 ? S 11:28 0:00 nginx: worker process
四、开机自启动
#在rc.local增加启动代码即可
vi /etc/rc.local
#增加一行 /usr/local/nginx/sbin/nginx,增加后保存
#设置执行权限
cd /etc
chmod 755 rc.local
浏览器输入服务器ip即可看到nginx欢迎界面

五、配置域名映射
#进入nginx配置文件目录,找到nginx的配置文件nginx.conf
cd /usr/local/nginx/conf/

#直接修改
vi nginx.conf

在文件中找到如图位置

#listen为监听的端口
listen 80;
#server_name为域名
server_name www.test.com;
#location是访问地址的设置,locahost也可以用服务器ip代替
location / {
proxy_pass http://localhost:8080;
}

如图,只需要修改server_name和location里面的内容即可

#修改完成后,重新加载配置文件
cd /usr/local/nginx/sbin/
./nginx -s reload

六、进入域名控制台,添加或者修改解析地址
如果原来配置了解析,新解析需要一定时间才能生效

注:收集于网络,侵权请联系作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值