CentOS7 安装 Nginx

一. 下载 Nginx 源码包

Nginx 官网
Nginx 下载页面
Nginx 1.23.4 下载链接

可以通过下载链接下载后上传至服务器内, 或者在服务器内使用 wget 命令下载
1
2
# 请根据实际情况替换链接 wget http://nginx.org/download/nginx-1.23.4.tar.gz

二. 解压并安装

  1. 安装所需依赖

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # 查看gcc版本 gcc -v # 如未安装 GCC, 则进行安装 yum -y install gcc # 安装 pcre pcre-devel yum install -y pcre pcre-devel # 安装 zlib yum install -y zlib zlib-devel # 安装 openssl yum install -y openssl openssl-devel
  2. 解压压缩包并安装

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 进入源码包目录, 如 /opt/nginx cd /opt/nginx # 解压压缩包(根据实际情况替换文件名) tar -zxvf nginx-1.23.4.tar.gz # 进入解压后的 nginx 目录中 cd nginx-1.23.4 # 编译并安装 ./configure make make install
  3. 启动 Nginx

    1
    2
    3
    4
    5
    6
    # 进入安装路径 cd /usr/local/nginx # 进入 Nginx 可执行文件路径 cd sbin # 启动 Nginx ./nginx
  4. 查看是否成功

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>

发表评论