Ubuntu18.04系统安装nginx

Ubuntu18.04系统安装nginx

  • 一、在线安装 Nginx
    • 1、 安装编译⼯具(nginx安装之前需要编译)
    • 2、安装PCRE
    • 3、安装SSL库
    • 4、安装zlib库
    • 5、安装Nginx
    • 6、启动Nginx
    • 7、停止Nginx
  • 二、在线安装 Nginx
  • 三、离线安装 Nginx
  • 参考链接

请确保以具有 sudo 权限的用户身份登录,并且您没有在端口 80443 上运行 Apache 或任何其他 Web 服务器。

一、在线安装 Nginx

1、 安装编译⼯具(nginx安装之前需要编译)

[root@zwp-server:~] yum install -y gcc gcc-c++

注意:ubuntu编译安装软件报错configure: error: Invalid C++ compiler or C++ compiler flags

  • ubuntu不像centos一样是gcc-c++,ubuntu的是build-essential。

  • 解决办法:

    //sudo apt-get update  --如果安装报错则需要更新apt-get
    sudo apt-get install build-essential
    

2、安装PCRE

# 1.下载
[root@zwp-server:local] wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
# 2.解压
[root@zwp-server:local] tar -zxvf pcre-8.45.tar.gz
# 3.进⼊pcre⽬录
[root@zwp-server:local] cd pcre-8.45
# 4.配置
[root@zwp-server:pcre-8.45] ./configure
# 5.编译安装
[root@zwp-server:pcre-8.45] make && make install

3、安装SSL库

[root@zwp-server:pcre-8.45] cd /usr/local
# 1.下载
[root@zwp-server:local] wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz
# 2.解压
[root@zwp-server:local] tar -zxvf openssl-1.1.1t.tar.gz
# 3.进⼊⽬录
[root@zwp-server:local] cd openssl-1.1.1t/
# 4.配置
[root@zwp-server:openssl-1.1.1t] ./config
# 5.编译安装
[root@zwp-server:openssl-1.1.1t] make && make install

4、安装zlib库

[root@zwp-server:openssl-1.1.1t] cd /usr/local
# 1.下载
[root@zwp-server:local] wget http://zlib.net/zlib-1.2.13.tar.gz
# 2.解压
[root@zwp-server:local] tar -zxvf zlib-1.2.13.tar.gz
# 3.进⼊⽬录
[root@zwp-server:local] cd zlib-1.2.13/
# 4.配置
[root@zwp-server:zlib-1.2.13] ./configure
# 5.编译安装
[root@zwp-server:zlib-1.2.13] make && make install

5、安装Nginx

[root@zwp-server:zlib-1.2.13] cd /usr/local
# 1.下载
[root@zwp-server:local] wget http://nginx.org/download/nginx-1.24.0.tar.gz
# 2.解压
[root@zwp-server:local] tar -zxvf nginx-1.24.0.tar.gz
# 创建nginx服务目录
[root@zwp-server:local] mkdir -p server/nginx
# 3.进⼊⽬录
[root@zwp-server:local] cd nginx-1.24.0/
# 4.配置
[root@zwp-server:nginx-1.24.0] ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.45
# 5.编译安装
[root@zwp-server:nginx-1.24.0] make && make install

注意: 如果在配置过程中出现了以下错误:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
# 执⾏:
yum -y install openssl openssl-devel

6、启动Nginx

Ubuntu18.04系统安装nginx_第1张图片

7、停止Nginx

在这里插入图片描述

二、在线安装 Nginx

简介:Nginx (engine x) 是一个免费的,开源的,高性能的 HTTP和反向代理 web服务器,同时也提供了IMAP/POP3/SMTP服务。

  1. Nginx 软件包在默认的 Ubuntu 存储库中可用。 安装非常简单。首先更新包列表,然后安装 Nginx。
sudo apt update

# 下面二选一
sudo apt install nginx 
sudo apt install -y nginx
  1. 查看Nginx版本与服务启动状态
# 查看nginx是否安装成功
nginx -v

# 查看nginx启动状态 --下面二选一
service nginx status 
systemctl status nginx

Ubuntu18.04系统安装nginx_第2张图片

  1. 在浏览器输入ip地址,如果正常出现Nginx默认的界面,表示可以正常使用了,Nginx安装成功!
    Ubuntu18.04系统安装nginx_第3张图片

  2. Nginx安装完成之后的文件位置

# nginx文件安装完成之后的文件位置:

/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志
  1. 卸载apt安装的Nginx
# 彻底卸载nginx
sudo apt --purge autoremove nginx
#查看nginx的版本号
nginx -v
  1. Nginx管理命令
# 要停止Nginx服务,请运行:
sudo systemctl stop nginx

# 要再次启动,请键入:
sudo systemctl start nginx

# 重新启动Nginx服务:
sudo systemctl restart nginx

# 在进行一些配置更改后重新加载Nginx服务:
sudo systemctl reload nginx

# 如果你想禁用Nginx服务在启动时启动:
sudo systemctl disable nginx

# 并重新启用它:
sudo systemctl enable nginx

三、离线安装 Nginx

https://blog.csdn.net/alfiy/article/details/123206823

参考链接

https://www.cnblogs.com/fireblackman/p/15692833.html

你可能感兴趣的:(Linux,nginx,运维,linux)