对于项目里面只是使用代理等常用功能,在线安装即可,如需制定化模块,则推荐编译安装
PS:本文不仅仅包含Nginx相关的知识点,还包含了逆天学习方法(对待新事物的处理)
官方网站:https://nginx.org/
Github:https://github.com/nginx/nginx
Nginx书籍:
Nginx Cookbook 中文版 https://huliuqing.gitbooks.io/complete-nginx-cookbook-zh/content/
Nginx官方中文文档 https://docshome.gitbooks.io/nginx-docs/content/
Nginx入门教程 https://xuexb.github.io/learn-nginx/
淘宝Nginx文档
1.在线安装
1.1.修改yum源地址
清华源:https://mirrors.tuna.tsinghua.edu.cn/help/centos/

更新软件包缓存:yum makecache

1.2.在线安装Nginx
在线安装比较简单,参考官方文档即可:https://nginx.org/en/linux_packages.html
PS:线上选stable的就行了,记得把$releasever改成你的版本号,eg:7

安装图示:

# 创建nginx的yum
vi /etc/yum.repos.d/nginx.repo
# 内容如下:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://nginx.org/keys/nginx_signing.key
# 在线安装
yum install nginx -y
1.3.端口放行
放行80端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
PS:规则生效:firewall-cmd --reload

1.4.验证安装

2.知识拓展
2.1.编译参数
离线安装可以参考在线安装的配置:nginx -V:编译参数(nginx -v:查看版本)

编译参数详解(点我展开)
```shell
# 1.编译选项
## Nginx的安装主目录
--prefix=http://www.likecs.com/etc/nginx \
## Nginx的执行文件路径
--sbin-path=http://www.likecs.com/usr/sbin/nginx \
## Nginx的模块目录
--modules-path=http://www.likecs.com/usr/lib64/nginx/modules \
## Nginx的配置文件路径
--conf-path=http://www.likecs.com/etc/nginx/nginx.conf \
## Nginx的错误日志路径
--error-log-path=http://www.likecs.com/var/log/nginx/error.log \
## Nginx的访问日志
--http-log-path=http://www.likecs.com/var/log/nginx/access.log \
## Nginx的pid文件路径
--pid-path=http://www.likecs.com/var/run/nginx.pid \
## Nginx的lock路径
--lock-path=http://www.likecs.com/var/run/nginx.lock \
# 2.编译选项(执行对应模块时Nginx缓存文件的存放地址)
--http-client-body-temp-path=http://www.likecs.com/var/cache/nginx/client_temp \
--http-proxy-temp-path=http://www.likecs.com/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=http://www.likecs.com/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=http://www.likecs.com/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=http://www.likecs.com/var/cache/nginx/scgi_temp \
# 3.设置Nginx权限组(虽然root权限安装,但可以指定nginx的运行权限)
--user=nginx \
--group=nginx \
# 4.优化
## 启用gzip压缩模块(常用)
--with-http_gzip_static_module \
--with-http_gunzip_module \
# 文件使用aio异步操作
--with-file-aio \
## C系列优化
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' \
## 设置附加的参数,链接系统库
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \
# HTTP内容替换
--with-http_sub_module \
# 其他优化选项 or 模块
--with-compat \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
```
2.2.安装目录