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=PATH: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