安装Nginx
编译环境gcc g++ 开发库之类的需要提前装好
Ubuntu:apt-get install build-essential
apt-get install libtool
centos: yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++
一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩
- 选定源码目录
cd /usr/local/src
- 安装PCRE库
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install
- 安装zlib库
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
- 安装ssl
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
- 安装nginx
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-file-aio \
--with-http_realip_module \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.44 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.1g
make -j2
make install
–with-pcre=/usr/local/src/pcre-8.44 指的是pcre-8.44 的源码路径。
–with-zlib=/usr/local/src/zlib-1.2.11指的是zlib-1.2.11 的源码路径。
启动Nginx
- 查看80端口是否被占用
netstat -ano|grep 80
- 启动nginx
sudo /usr/local/nginx/nginx
用浏览器访问安装nginx的ip,出现
即nginx安装成功,且启动成功
nginx.config
三部分组成
-
全局块
配置文件开始到event块之间
影响nginx服务器整体运行的配置指令,主要包括配置运行Nginx服务器的用户组、运行生成worker process数,进程PID 存放路径 日志保存和类型以及配置文件的引入等worker process:处理并发量
-
event{}
主要影响Nginx服务器与用户的网络连接
比如:worker connection :支持最大连接数 -
http{}
http全局、server{ location{} }
server{
listen : //监听端口
server_name //应用名称
location / {
}
}
反向代理
请求转发 和 代理静态资源 (https)
用OpenSSL生成 公钥和私钥
git自带OpenSSL