Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我
所有文章 外链

Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我

CentOS7离线安装Nginx

阅读数:次 2019-04-20
字数统计: 979字   |   阅读时长≈ 4分

目录

1.概览
2.详情
–2.1安装依赖
—-2.1.1安装gcc
—-2.1.2安装pcre
—-2.1.3安装libstdc++(gcc-c++依赖)
—-2.1.4安装gcc-c++
—-2.1.5安装zlib
–2.2 安装nginx
–2.3 常用命令
–2.4 关闭Nginx代理服务器防火墙
–2.5 端口验证
–2.6 自启动设置

1.概览

服务器无法访问外网,nginx只能离线装,步骤如下:

离线状态,可先联网下载需要的依赖,需要的依赖包括:gcc、pcre、libstdc++、libstdc++-devel、gcc-c++、zlib,下载地址https://pkgs.org,选择对应的系统版本下载。

注意:

  • 1.统一使用rpm格式;
  • 2.各种依赖版本务必统一;
  • 3.服务器如果在安装时没有点选一些模块,可能需要下载的东西较多,在服务器性能允许的情况下,建议全选安装;
  • 4.服务器上已有的一些依赖,版本通常较低,rpm安装时可使用 --force 强制升级安装。

2.详情

2.1安装依赖

2.1.1安装gcc

1
rpm -ivh gcc-4.8.5-36.el7.x86_64.rpm

2.1.2安装pcre

1
2
3
4
# 由于机器上已经有低版本的pcre,所以强制安装
rpm -ivh pcre-8.32-17.el7.x86_64.rpm --force

rpm -ivh pcre-devel-8.32-17.el7.x86_64.rpm --force

2.1.3安装libstdc++(gcc-c++依赖)

1
2
rpm -ivh libstdc++-4.8.5-36.el7.x86_64.rpm --force
rpm -ivh libstdc++-devel-4.8.5-36.el7.x86_64.rpm --force

2.1.4安装gcc-c++

1
rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm --force

2.1.5安装zlib

1
2
3
rpm -ivh zlib-1.2.3-29.el6.x86_64.rpm

rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm

2.2 安装nginx

从Nginx官网下载最新Stable版本,本次下载安装版本为1.41.2(20190417)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 下载解压

tar -xzvf nginx-1.14.2.tar.gz

# 移动源代码到对应目录下
sudo mv /path/to/nginx-1.14.2 /usr/local/
cd /usr/local/nginx-1.14.2
#
./configure
# 编译
make
#安装
make install

# 运行nginx
cd /usr/local/nginx/sbin
./nginx

8.验证

检查nginx.conf配置文件是否正确。

1
/usr/local/nginx/sbin/nginx  -t

正确之后,浏览器打开localhost:8080,如果可访问 welcome to nginx 页面,表示配置完成。

2.3 常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 通过help查看常用命令
/usr/local/nginx/sbin/nginx -h

Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
1
2
3
4
5
6
7
./nginx -v  显示nginx的版本号
./nginx -V 显示nginx的版本号和编译信息
./nginx -t 检查nginx配置文件的正确性
./nginx -t 检查nginx配置文件的正确定及配置文件的详细配置内容
./nginx -s 向主进程发送信号,如:./nginx -s reload 配置文件变化后重新加载配置文件并重启nginx服务
./nginx -p 设置nginx的安装路径
./nginx -c 设置nginx配置文件的路径

2.4 关闭Nginx代理服务器防火墙

1
2
3
4
5
6
7
8
# 临时关闭
systemctl stop firewalld.service

# 禁止开机启动
systemctl disable firewalld

# 查看防火墙状态
systemctl status firewalld

2.5 端口验证

确保映射需要的端口到外网,如80、8080、8081

2.6 自启动设置

1、在系统服务目录里创建nginx.service文件

1
vim  /usr/lib/systemd/system/nginx.service

2、写入内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3、设置开机自启动

1
systemctl enable nginx.service

4、查看Nginx状态

1
systemctl status nginx.service

很奇怪,明明启动成功了,为什么显示Active: inactive (dead)?

5、杀死Nginx重启Nginx

1
2
3
pkill  -9  nginx
ps aux | grep nginx
systemctl start nginx

再次查看状态,变成了active。

6、重启服务器测试效果

1
reboot                      

7、再次连接后,查看服务状态

1
systemctl  status  nginx.service

看到Nginx已经启动,至此,Nginx自启动配置成功。

  • 本文作者: Linking
  • 本文链接: https://linking.fun/2019/04/20/CentOS7离线安装Nginx/
  • 版权声明: 版权所有,转载请注明出处!
  • Nginx
  • cs

扫一扫,分享到微信

应用服务器集群时钟同步
应用系统部署文档模板
  1. 1. 1.概览
  2. 2. 2.详情
    1. 2.1. 2.1安装依赖
      1. 2.1.1. 2.1.1安装gcc
      2. 2.1.2. 2.1.2安装pcre
      3. 2.1.3. 2.1.3安装libstdc++(gcc-c++依赖)
      4. 2.1.4. 2.1.4安装gcc-c++
      5. 2.1.5. 2.1.5安装zlib
    2. 2.2. 2.2 安装nginx
    3. 2.3. 2.3 常用命令
    4. 2.4. 2.4 关闭Nginx代理服务器防火墙
    5. 2.5. 2.5 端口验证
    6. 2.6. 2.6 自启动设置
© 2015-2026 Linking
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量次 | 本站访客数人
  • 所有文章
  • 外链

tag:

  • weather
  • 需求
  • essay
  • basketball
  • olympic
  • nginx
  • APPScan
  • SQl盲注
  • xss
  • Ajax
  • ajax
  • ai
  • agent
  • openclaw
  • ccf
  • Nginx
  • HTML5
  • html5
  • hmtl5
  • sse
  • JavaScriptCore
  • Oracle
  • operation
  • Linux
  • deploy
  • Mac Office
  • markdown
  • ListView
  • GridView
  • MySQL
  • 慢查询
  • mongodb
  • 转置
  • thought
  • network
  • ubuntu
  • NetworkManager
  • RFKill
  • Netplan
  • avatar
  • cocoa
  • blog
  • Gitalk
  • container
  • macvlan
  • docker
  • oracle
  • cookie
  • patch
  • gitea
  • git
  • iOS
  • https
  • 多线程
  • bundle
  • 兼容性
  • HTTP
  • 绘图
  • cs
  • java
  • 效率
  • 快捷键
  • route
  • nodejs
  • pip
  • arcgis
  • arcgis 建模
  • 标识
  • redis
  • read
  • bookList
  • running
  • showdoc
  • disk
  • unit-test
  • D.Wade
  • thoughts
  • duoduo
  • Python
  • python
  • tomcat
  • 读书节
  • session
  • jdk
  • war
  • 加班
  • Android onclick事件监听
  • 正则
  • 手机品牌匹配
  • ntp
  • OpenLayers
  • Geoserver
  • wechat
  • 微信公众号
  • 爬虫
  • WeChat
  • 张靓颖
  • 动漫
  • vpn
  • PPT
  • MarkDown
  • plan
  • 朱赟
  • 极客时间专栏
  • 极客邦
  • 模块化
  • MVC
  • excel
  • NBA
  • kobe
  • team
  • crawler
  • 进度条
  • ssl
  • book
  • anti-stealing-link
  • Agentic Engineering
  • Vibe Coding
  • Software 3.0
  • Andrej Karpathy
  • LLM
  • Programming

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia-plus根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • GitHub Trending
  • OpenAI ChatGPT
  • Gitee码云
  • 简书
  • CSDN