树莓派安装的CentOS用不了第三方软件园,只好通过make install
安装nginx
1. 下载nginx软件源码:
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar xf nginx-1.10.3.tar.gz
2. 利用yum 安装pcre pcre-devel openssl 等包
yum install pcre pcre-devel openssl openssl-devel gcc -y
3. 开始安装
cd nginx-1.10.3
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
4. 配置
cd /usr/local/nginx/conf
sed -n 30,40p nginx.conf
//检查语法
/usr/local/nginx/sbin/nginx -t
输出:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
则为配置正确,但是有可能会报错:
[emerg] getpwnam("nginx") failed
错误的原因是没有创建nginx这个用户
,应该在服务器系统中添加nginx用户组和用户nginx,如下命令:
/usr/sbin/groupadd -f nginx
/usr/sbin/useradd -g nginx nginx
5. 启动nginx服务:
/usr/local/nginx/sbin/nginx
启动后查看是否运行成功:
ps aux | grep nginx
//输出
root 4034 0.0 0.1 8144 1852 ? Ss 12:13 0:00 nginx: master process ./sbin/nginx
nginx 4035 0.0 0.3 8284 2908 ? S 12:13 0:00 nginx: worker process
root 4121 0.0 0.0 2680 572 pts/0 S+ 12:29 0:00 grep --color=auto nginx
可以访问本地端口试试:
curl -I localhost:80
//输出
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Thu, 05 Oct 2017 12:13:55 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 05 Oct 2017 11:00:46 GMT
Connection: keep-alive
ETag: "59d610de-264"
Accept-Ranges: bytes