yum install gcc-c++2、安装依赖包
yum install -y openssl openssl-devel pcre pcre-devel zlib zlib-devel3、安装nginx
1、在/usr/local/下创建目录
mkdir /usr/local/nginx
2、在网上下 nginx 包上传至 Linux服务器 (https://nginx.org/download/),也可以直接下载
wget https://nginx.org/download/nginx-1.19.9.tar.gz
3、解压并进入 nginx 目录
tar -zxvf nginx-1.19.9.tar.gz cd nginx-1.19.9
4、使用 nginx 默认配置
./configure
5、编译安装
make make install
6、查找安装路径
whereis nginx
默认路径为 /usr/local/nginx/
7、进入 sbin 目录,执行nginx。
cd /usr/local/nginx/sbin ./nginx
也可以指定配置文件路径
./nginx -c /usr/local/nginx/conf/nginx.conf
8、查看是否启动成功
ps -ef | grep nginx
9、在网页上访问服务器的 IP 就可以了,默认80端口
10、重启nginx
./nginx -s reload
带配置文件路径的重启
./nginx -s reload -c /usr/local/nginx/conf/nginx.conf
11、停止nginx
./nginx -s stop
12、配置开机启动
在/etc/rc.d/rc.local中添加nginx启动命令行:
vi /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx
保存并退出,下次重启会生效。
4、修改配置文件配置文件所在位置
/usr/local/nginx/conf/nginx.conf
检查配置文件是否正确
./nginx -t使用示例:
配置多个域名到同一个端口号
# nginx 80端口配置 (监听域名demo1.test.com)
server {
listen 80;
server_name demo1.test.com;
root /home/project1;
location / {
root /home/project1;
index index.html index.htm;
}
}
# nginx 80端口配置 (监听域名demo2.test.com)
server {
listen 80;
server_name demo2.test.com;
root /home/project2;
location / {
root /home/project2;
index index.html index.htm;
}
}
# nginx 80端口配置 (监听域名demo3.test.com)
server {
listen 80;
server_name demo3.test.com;
location / {
proxy_pass http://localhost:8081; # 转发
}
}



