学习原因
对于nginx,只是用来做反向代理、简单的负载均衡,其原理核心不是很了解,原因我是个前端开发者,如果不是使用了node估计这辈子都不会接触nginx。现在回忆起自己的面试经历之惨痛,对于需要的拿来就用能解决问题就好、不会深入理解的认知事物的方式深恶痛绝。
安装
centos 7
nginx下载地址 version 1.14
编译前安装依赖:
yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
编译指令:
在解压包里的configure执行文件中有安装的相关配置项,更改目录什么的都在里面。
configure官方文档
不使用官网的二进制文件的原因是无法扩展第三方模块
官方二进制版本安装路径:/etc/nginx
编译版本路径:/usr/local/nginx
./configure #检查编译模块/依赖是否缺失
make
make install
启动命令
/usr/local/nginx/sbin/nginx
或者
vi /etc/profile
export NGINX=/usr/local/nginx/sbin
export PATH=$PATH:$NGINX
source /etc/profile
配置服务
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.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 stop
[Install]
WantedBy=multi-user.target
将以上代码保存到
/usr/lib/systemd/system/nginx.service
文件中
启动 systemctl start nginx
自启 systemctl enable nginx