centos8部署nginx

Nginx 部署

1.创建 www用户, UID、GID 皆是 501,通过cat /etc/passwd,检查是否存在www用户

~]# groupadd -g 501 www
~]# useradd -u 501 -g www www
~]# cat /etc/passwd

2.下载相应版本

~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz

3.解压到/usr/local/src

~]# tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/src

4.安装依赖包,然后进入到目录进行编译安装

~]#yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
~]# cd /usr/local/src/nginx-1.16.1
~]# ./configure --user=www --group=www --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_v2_module --prefix=/usr/local/webserver/nginx
~]# make && make install

5.创建sites目录–sites目录放每个项目的配置文件

~]# cd /usr/local/webserver/nginx/conf/
~]# mkdir sites
~]# vim /usr/local/webserver/nginx/conf/nginx.conf
文件开头添加:
user www;
文件中差不多末尾的那里引入:
include sites/*.conf

6.设置nginx环境变量,并加载环境变量

~]# vim /etc/profile.d/nginx.sh
export NGINX_HOME=’/usr/local/webserver/nginx’
export PATH= P A T H : PATH: PATH:NGINX_HOME/sbin

注意:$PATH 符号
~]# . /etc/profile.d/nginx.sh

7.校验nginx,

~]# nginx -t
重启—每次添加配置文件后都要重启nginx
~]# nginx -s reload

8.设置好nginx开机自启

~]# vim /etc/rc.d/rc.local
/usr/local/webserver/nginx/sbin/nginx
~]#chmod +x /etc/rc.d/rc.local

9.上面提到的添加某个项目配置文件

~]# cd /usr/local/webserver/nginx/conf/
~]# vim 域名.conf
配置文件内容:主要修改域名和项目目录
server {
listen 80;
server_name yuepengcheng.club;
index index.html index.htm;
root /www/wwwroot/qipan1.zhijiatechnology.xyz;
location = /favicon.ico {
log_not_found off;
access_log off;
break;
}
}
!!!!!!!!!!!!!!!!!!!!!!!一定要重启!!!!!!!!!!!!!!!!!!!!!!
配置完:nginx -t
重启:nginx -s reload

绑定多个域名的时候直接以空格分开就好。

一定要开放80端口:-------------------------------------------------
firewall-cmd --zone=public --add-port=80/tcp --permanent
开放之后重启:
firewall-cmd --reload
查看:
firewall-cmd --zone=public --list-ports

新服务器第一时间看下防火墙,可能需要关闭防火墙
centos7:
查看防火墙
systemctl status firewalld.service
关闭防火墙
systemctl stop firewalld.service

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值