1、下载安装包
上传到安装目录
或
在线下载:wget http://nginx.org/download/nginx-1.24.0.tar.gz
如:
????????安装目录:/usr/local/software
解压安装包:
tar -zxvf nginx-1.24.0.tar.gz
先安装基础依赖
#安装gcc
yum install gcc-c++
#安装PCRE pcre-devel
yum install -y pcre pcre-devel
#安装zlib
yum install -y zlib zlib-devel
#安装Open SSL
yum install -y openssl openssl-devel
进入安装包解压目录:
cd nginx-1.24.0
编译 执行命令 考虑到后续安装ssl证书 添加两个模块 ?如不需要直接执行./configure即可
#配置configure --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,
# --with-http_stub_status_module查看nginx的客户端状态
./configure --prefix=/usr/local/software/nginx --with-http_ssl_module --with-http_stub_status_module
执行make命令(要是执行不成功请检查最开始安装的四个依赖有没有安装成功)
make
执行make install命令
make install
进入安装目录
cd /usr/local/software/nginx
上面 configure 命令配置的目录
进入配置文件目录,修改配置
cd conf
# 编辑配置文件
vim nginx.conf
修改nginx.conf,主要添加自定义配置文件目录:include ../conf.d/*.conf;
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# 引入多个配置文件,上级目录conf.d下所有配置
include ../conf.d/*.conf;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
}
创建目录?conf.d?
目录结构如下
在?conf.d 目录下创建 自定义配置文件 xxx.conf
server {
listen 8888;
server_name localhost;
# 设置上传文件大小,0表示不限制
client_max_body_size 0;
# app站点
location /api/ {
proxy_pass http://127.0.0.1:9999/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
proxy_redirect off;
}
location / {
root /usr/local/server/front;
index index.html index.htm;
}
}
进入 sbin 目录
# 启动 nginx
./nginx
# 停止指令
./nginx -s stop
# 或
./nginx -s quit
# 重启命令
./nginx -s reload
# 查看nginx进程
ps -ef|grep nginx
# 检查配置文件
./nginx -t
遇到的问题:
1、报错
+ Linux 3.10.0-1160.76.1.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解放方法:
#执行下面命令解决问题
yum -y install gcc gcc-c++ autoconf automake make
2、报错?make: *** No rule to make target `build', needed by `default'. ?Stop.
make: *** No rule to make target `build', needed by `default'. Stop.
解决方法:
yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel