layout: post
#标题配置
title: Nginx安装与部署项目
#时间配置
date: 2021-08-23 23:01:00 +0800
#目录配置
categories: JavaWeb
#标签配置
tag: 教程
Nginx安装
1.上传压缩包:
put d:/nginx-1.20.1.tar.gz
2.解压压缩包:
移动到home目录:
mv nginx-1.20.1.tar.gz /home/
cd /home/
tar -zxvf nginx-1.20.1.tar.gz
3.进入解压目录:
cd nginx-1.20.1
4.安装依赖环境
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
补充:(执行./configure时出现checking for C compiler … not found)
yum -y install gcc-c++
5.安装nginx
./configure
make
make install (安装完会在/usr/local/下有一个nginx目录)
6.启动nginx服务:
cd /usr/local/nginx/sbin
启动
./nginx
停止
./nginx -s stop
重启
./nginx -s reload
7.查看nginx服务状态:
ps -ef | grep nginx
8.测试nginx服务:
防火墙设置
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙
systemctl restart firewalld.service
http://192.168.203,138
发布项目
1.在/home下创建一个目录:
cd /home/
2.将项目上传到该目录下:
put G:/实训项目/UOLabNUC2020.zip
新开一个ssh窗口
移动到home下
mv UOLabNUC2020.zip /home/
cd /home/
3.解压项目压缩包:
unzip UOLabNUC2020.zip
4.编辑nginx配置文件:
vi /home/nginx-1.20.1/conf/nginx.conf
找到 server的大括号范围,修改location的路径
server {
1isten 80;
serwer_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/UOLabNUC2020; //修改此处
index index.html index.htm;
5.关闭nginx服务:
cd /usr/local/nginx/sbin
./nginx -s stop
6.启动nginx服务并加载配置文件:
/usr/local/nginx/sbin/nginx -c /home/nginx-1.20.1/conf/nginx.conf
7.通过浏览器测透网站: http://192.168.203.138