Nginx 安装
1、执行命令 cd /usr/local
2、安装 gcc 和 gcc-c++
yum install gcc
yum install -y gcc gcc-c++
3、安装pcre 库
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
cd pcre-8.39/
./configure
make && make install
4、安装zlib
wget http://zlib.net/zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure
make && make install
5、安装openSSL
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
cd openssl-1.0.1t
./config
make && make install
(如果说缺少 perl 则安装perl
yum install -y perl
Yum install -y cpan )
6、安装nginx
下载 wget http://nginx.org/download/nginx-1.10.1.tar.gz
解压
tar -xzvf nginx-1.10.1.tar.gz
mv nginx-1.10.1.tar.gz nginx
./configure
make && make install
7、启动nginx
启动 /usr/local/nginx/sbin/nginx
或者在后加 -c /usr/local/nginx/conf/nginx.conf
(-c制定配置文件的路径,不加-nginx会自动加载默认路径的配置文件)
停止 /usr/local/nginx/sbin/nginx -s stop
重新加载配置 /usr/local/nginx/sbin/nginx -s reload
配置文件检测/usr/local/nginx/sbin/nginx -t
8、开机自动启动及快捷方式
在/usr/lib/systemd/system下创建nginx.service文件,内容如下:
[Unit]
Description=nginx -web server
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
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=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
或者
[Unit]
Description=nginx -web server
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
Environment=PIDFile=/usr/local/nginx/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
说明
[Unit]
Description : 服务的简单描述
Documentation : 服务文档
After= : 依赖,仅当依赖的服务启动之后再启动自定义的服务单元
[Service]
Type : 启动类型simple、forking、oneshot、notify、dbus
ExecStartPre :启动前要做什么,上文中是测试配置文件 -t
ExecStart:启动
ExecReload:重载
ExecStop:停止
PrivateTmp:True表示给服务分配独立的临时空间
[Install]
WantedBy:服务安装的用户模式,multi-user.target ,指使用这个服务的目录是多用户
再执行
systemctl enable nginx.service
就会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。
启动 systemctl start nginx.service
停止systemctl stop nginx.service
重载 systemctl restart nginx.service