Nginx编译和安装(超简单版)

 

预编译
make
make install 

下载nginx源码包
nginx网站:http://nginx.org/en/download.html

      wget http://nginx.org/download/nginx-1.16.1.tar.gz

下载文件
tar xf nginx-1.16.1.tar.gz  # 解压
cd nginx-1.16.1 # 切到目录下



# 执行   [root@wy
~/nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --with-http_ssl_module

可能会出错,在执行之前可执行
  yum install -y pcre pcre-devel
  yum install openssl openssl-devel -y

这两条命令,再执行
  [root@wy ~/nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --with-http_ssl_module
 

可能会出现的错误
# 执行绿色的可执行文件
------出现错误 ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
-----解决方法   yum install -y pcre pcre-devel

 # 重新执行

   [root@wy ~/nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --with-http_ssl_module



---出现错误
./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 install openssl openssl-devel -y
# 重新执行   [root@wy
~/nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --with-http_ssl_module


没有问题后执行:
[root@wy ~/nginx-1.16.1]# echo $?
# 如果等于0,则没有问题
[root@wy ~/nginx-1.16.1]# make
[root@wy ~/nginx-1.16.1]# echo $?
[root@wy ~/nginx-1.16.1]# make install
[root@wy ~/nginx-1.16.1]# echo $?

查看自动创建的app目录
[root@wy ~/nginx-1.16.1]# ll /app/nginx-1.16.1/
total 4
drwxr-xr-x. 2 root root 4096 Aug 20 19:55 conf
drwxr-xr-x. 2 root root   40 Aug 20 19:55 html
drwxr-xr-x. 2 root root    6 Aug 20 19:55 logs
drwxr-xr-x. 2 root root   19 Aug 20 19:55 sbin

编译安装要启动觉得路径去启动,先创建软连接
[root@wy ~/nginx-1.16.1]# ln -s /app/nginx-1.16.1/ /app/nginx
[root@wy ~/nginx-1.16.1]# /app/nginx/sbin/nginx
[root@wy ~/nginx-1.16.1]# ss -lntp|grep 80
LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=13559,fd=6),("nginx",pid=13558,fd=6))

默认80  访问:10.0.0.100
[root@wy ~/nginx-1.16.1]# systemctl status firewalld  # 查看防火墙
[root@wy ~/nginx-1.16.1]# systemctl stop firewalld # 关闭防火墙
[root@wy ~/nginx-1.16.1]# systemctl disable firewalld # 不自启动

 

原文地址:https://www.cnblogs.com/tuzaizi/p/13167555.html