1. 安装源码编译工具及库
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2. 安装PCRE(Perl)
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz
cd ./pcre-8.35
./configure
make&make install
pcre-config --version
3. 下载nginx源码
http://mirrors.sohu.com/nginx/nginx-1.16.0.tar.gz
同上源码安装
tar
cd
configure
make&make install
进入相关路径启动nginx服务
[root@leyshine sbin]# pwd
/usr/local/nginx/sbin
[root@leyshine sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
发生错误!!!端口被占用–HTTPD
[root@leyshine sbin]# netstat -ltnp | grep "80"
tcp6 0 0 :::80 :::* LISTEN 1090/httpd
[root@leyshine sbin]# kill 1090
[root@leyshine sbin]# ./nginx
[root@leyshine sbin]# ./nginx -v
nginx version: nginx/1.16.1
[root@leyshine sbin]# netstat -ltnp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12908/nginx: master
[root@leyshine sbin]# ps aux | grep nginx
root 12908 0.0 0.0 20556 612 ? Ss 07:45 0:00 nginx: master process ./nginx
nobody 12909 0.0 0.0 23092 1388 ? S 07:45 0:00 nginx: worker process
root 12924 0.0 0.0 112716 960 pts/2 S+ 07:46 0:00 grep --color=auto nginx
5 测试打开首页
[root@leyshine /]# curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
6.开机启动
[root@leyshine system]# pwd
/usr/lib/systemd/system
[root@leyshine system]# vim nginx.service
[root@leyshine system]# cat nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@leyshine system]# systemctl start nginx
[root@leyshine system]# systemctl status nginx
● nginx.service - nginx
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-02-05 08:13:31 HKT; 12s ago
Process: 13399 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 13401 (nginx)
Tasks: 2
CGroup: /system.slice/nginx.service
├─13401 nginx: master process /usr/local/nginx/sbin/nginx
└─13402 nginx: worker process
Feb 05 08:13:31 leyshine.com systemd[1]: Starting nginx...
Feb 05 08:13:31 leyshine.com systemd[1]: Started nginx.
systemctl enable nginx.service