一、下载nginx的官方软件bao
社区版:http://www.nginx.org
企业版:http://www.nginx.com
二、安装nginx
安装依赖库
# yum -y install pcre-devel zlib-devel openssl-devel
使用nginx.sh安装Nginx
#!/bin/bash
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
useradd -r -s /sbin/nologin www
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
make && make install
–prefix:安装路径
–user:以哪个用户身份安装初始化
–group:以哪个用户组身份安装初始化
–with-*:代表安装哪些模块(默认情况下只安装基本模块)
nginx目录:
[root@master ~]# cd /usr/local/nginx/
[root@master nginx]# ls
conf html logs sbin
conf:配置文件主目录,Nginx主配置文件nginx.conf。当Nginx启动时,会
自动加载nginx.conf文件
html:项目目录,项目的源代码就存放于此目录下
logs:日志目录,error.log错误日志与access.log访问日志
sbin:二进制文件目录,Nginx的主程序sbin/nginx
查看nginx的帮助
[root@master nginx]# sbin/nginx -h
nginx version: nginx/1.12.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
-V:显示Nginx的版本与配置的选项信息
-t:检查nginx.conf的语法
-s:发送信号,stop(停止)、quit(优雅的退出)、reopen(重新打开配置文件)、reload(热重载配置文件)
-c:加载配置文件
扩展nginx.service脚本
创建nginx.service脚本
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx Web Server
After=network.target
[Service]
Type=forking #表示后台运行
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动nginx
# systemctl satrt nginx.service
# systemctl status nginx.service
# systemctl enable nginx