安装环境为:最小化安装的centos7。
开始安装Nginx
1 2 3 4 5 6 7 8 9 10 11 |
创建群组 groupadd www 创建一个用户,不允许登陆和不创主目录 useradd -s /sbin/nologin -g www -M www #下载最新版Nginx wget -C https://Nginx.org/download/Nginx-1.7.8.tar.gz tar zxvf Nginx-1.7.8.tar.gz #编译基本能运行的Nginx ./configure --user=www --group=www --prefix=/usr/local/Nginx --with-https_stub_status_module --with-https_ssl_module --with-https_gzip_static_module make make install |
./configure: error: C compiler cc is not found
解决方法:
1 |
yum install gcc gcc-c++ |
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using –without-https_rewrite_module
option,or install the PCRE library into the system,or build the PCRE library
statically from the source with Nginx by using –with-pcre=<path> option.
解决方法:
1 |
yum install pcre-devel |
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules,or install the OpenSSL library
into the system,or build the OpenSSL library statically from the source
with Nginx by using –with-openssl=<path> option.
解决方法:
1 |
yum install openssl-devel |
1 2 3 |
./configure --user=www --group=www --prefix=/usr/local/Nginx --with-https_stub_status_module --with-https_ssl_module --with-https_gzip_static_module make make install |
编译参数解释:
1 2 3 4 5 6 7 8 9 10 11 12 |
#指定运行权限的用户 --user=www #指定运行的权限用户组 --group=www #指定安装路径 --prefix=/usr/local/Nginx --with-https_stub_status_module #开启ssl支持 --with-https_ssl_module #开启GZIP功能 --with-https_gzip_static_module |
因此要顺利的通过Nginx编译安装必须安装的依赖关系有:
1 |
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel |
2、在 centos7 中为Nginx的启动、重启、重载配置添加脚本
1 |
但是不是很方便,因此使用下面的脚本来控制Nginx的启动关闭重载更加合理一些。
编辑文件:vim /usr/lib/systemd/system/Nginx.service 添加下面的脚本,注意路径 !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[Unit] Description=Nginx - high performance web server Documentation=https://Nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/Nginx/logs/Nginx.pid ExecStartPre=/usr/local/Nginx/sbin/Nginx -t -c /usr/local/Nginx/conf/Nginx.conf ExecStart=/usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target |
systemctl的一些使用方法:
1 2 3 4 5 6 7 8 9 |
systemctl is-enabled servicename.service #查询服务是否开机启动 systemctl enable xxx.service #开机运行服务 systemctl disable xxx.service #取消开机运行 systemctl start xxx.service #启动服务 systemctl stop xxx.service #停止服务 systemctl restart xxx.service #重启服务 systemctl reload xxx.service #重新加载服务配置文件 systemctl status xxx.service #查询服务运行状态 |
因此,添加上面脚本后,centos7 中操作Nginx的方法有
1 2 3 4 5 6 7 8 9 |
systemctl is-enabled Nginx.service #查询Nginx是否开机启动 systemctl enable Nginx.service #开机运行Nginx systemctl disable Nginx.service #取消开机运行Nginx systemctl start Nginx.service #启动Nginx systemctl stop Nginx.service #停止Nginx systemctl restart Nginx.service #重启Nginx systemctl reload Nginx.service #重新加载Nginx配置文件 |
copyright={ "作者":"墨衣夜行","本文链接":"http://my.oschina.net/letao/blog/524487" }原文链接:https://www.f2er.com/centos/381809.html