栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux安装nginx

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux安装nginx

1、安装 gcc-c++编译器
yum install gcc-c++
2、安装依赖包
yum install -y openssl openssl-devel pcre pcre-devel zlib zlib-devel
3、安装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; # 转发
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/882594.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号