Nginx使用记录
1、安装依赖
sudo yum -y install openssl openssl-devel pcre pcre-devel zlib zlib-devel gcc gcc-c++
2、解压并安装
–prefix=要安装到的目录
1、./configure --prefix=/opt/module/nginx
2、make && make install
3、启动Nginx
cd /opt/module/nginx/sbin
./nginx
4、查看启动情况 2种
ps -ef |grep nginx
浏览器输入:http://111.111.11.111/ (输入节点ip)
5、Nginx其他使用命令
重启
./nginx -s reload
关闭
./nginx -s stop
配置文件启动
./nginx -c /opt/module/nginx/conf/nginx.conf
配置检查
./nginx -c /opt/module/nginx/conf/nginx.conf -t
6、使用时常见问题解决
如果在非root用户下启动会报错
原因:nginx占用80端口,默认情况下非root用户不允许使用1024以下端口
解决:sudo setcap cap_net_bind_service=+eip /opt/module/nginx/sbin/nginx
如果80端口被占用,需要停掉httpd服务
sudo systemctl stop httpd
sudo systemctl disable httpd
其他错误
**error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory**
解决:ln -s /usr/local/lib/libpcre.so.1 /lib64
7、配置文件简单介绍
基本项
user nobody 一般用于启动程序, 注掉
worker_processes 1;配置工作进程的数目,通常等于CPU数量或者2倍于CPU数量
error_log 配置全局错误日志及类型,【debug | info | notice | warn | error | crit】,默认error,注掉
pip 配置pip文件,注掉
events配置
配置每个worker进程连接数上限
http配置
server配置(可配置多个)