通过Xftp 7吧安装包放到指定位置
#
tar -zxvf nginx-1.18.0.tar.gz
# 进入nginx-1.18.0内部文件夹内
cd nginx-1.18.0
#指定安装到哪里,默认直接 ./configure
./configure --prefix=/usr/local/nginx-1.18.0
- 编译安装
- 通过命令:make && make install 编译安装。
- `备注:make 编译安装时出现:
make: *** No rule to make target build', needed bydefault'. Stop.
是缺少必要的环境文件,通过执行如下命令重新制定地址编译完成安装:
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
./configure --prefix=/usr/local/nginx-1.18.0
make && make install
- 配置:
- cd /usr/local/nginx-1.18.0
有四个文件夹:
conf:配置文件 html:存放前端代码 logs:日志文件夹 sbin:系统相关文件
配置主要改conf文件下的nginx.conf,一般修改端口号相关的代码映射地址等。
`
listen 端口号(默认80,视情况更改)
location 前端代码映射地址(服务器上代码存放的绝对地址)
多个项目可配置多个location,转到指定地址用proxy_pass url
- 启动
- 进入nginx 的sbin目录执行:./nginx 启动
cd sbin
./nginx
ps -ef|grep nginx #查看进程
如果启动的时候报错可参考
nginx: [alert] could not open error log file: open() "/usr/local/nginx-1.20.1/logs/error.log" failed (2: No such file or directory)
[emerg] 6636#0: open() "/usr/local/nginx-1.20.1/logs/access.log" failed (2: No such file or directory)
这句话是缺少了error.log错误日志
在当前文件夹建
/usr/local/nginx-1.18.0/logs/error.log
# 附加参考命令
cd /usr/local/nginx/sbin/
./nginx # 启动
./nginx -s stop # 强制停止(使用kill命令强制杀掉进程)
./nginx -s quit # 友好停止(处理任务完毕进行停止)
./nginx -s reload # 重新加载(用于nginx.conf 修改后)