Linux安装nginx

Linux安装nginx

1、方式一:自定义可执行文件目录

  • 复制nginx压缩包到linux

  • 安装编译工具

# root用户身份登录
su   root
# 输入以下安装指令
yum -y install zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel automake autoconf libtool pcre*
  • 解压nginx
tar  -zxvf nginx-1.12.2.tar.gz
  • 配置安装可执行文件目录
# 新建安装目录
mkdir /home/Ywee/nginx-bin
# 切换到nginx的解压目录
cd /home/Ywee/software/nginx-1.12.2
# 配置可执行文件目录
./configure  --prefix=/home/Ywee/nginx-bin
  • 安装nginx
# 切换到nginx的解压目录
cd /home/Ywee/software/nginx-1.12.2
# 安装
make  &&  make install
  • 编辑配置文件
# 切换到nginx可执行文件目录
cd /home/Ywee/nginx-bin
# 编辑nginx.conf
vim   conf/nginx.conf

将nobody改为root,并且取消注释

  • 运行nginx进程
# 切换到nginx安装可执行文件目录
cd /home/Ywee/nginx-bin/sbin
# 启动nginx进程
./nginx
  • 查看nginx的进程及端口
netstat -ntlp # 查看nginx端口
ps -aux # 查看nginx的进程
  • 浏览器访问:http://虚拟机ip地址:nginx端口(80),本地主机浏览器访问需要关闭Linux防火墙

2、方式二:默认可执行文件目录

  • 复制nginx压缩包到Linux

  • 解压

  • cd到解压目录,进行自动配置

./configure 
  • 如果报错:./configure: error: the HTTP rewrite module requires the PCRE library.执行以下命令
yum -y install pcre-devel
  • 如果报错:./configure: error: the HTTP gzip module requires the zlib library.执行以下命令
yum install -y zlib-devel
  • 解决报错之后重新配置
./configure 
  • 安装
make
make install
  • 查看nginx安装目录,并启动nginx
[root@node1 nginx-1.18.0]# whereis nginx # 查看nginx安装目录
nginx: /usr/local/nginx
[root@node1 nginx-1.18.0]# cd /usr/local/nginx # cd到安装目录
[root@node1 nginx]# ls # 查看目录下的文件
conf  html  logs  sbin
[root@node1 nginx]# cd sbin # cd到可执行文件目录
[root@node1 sbin]# ls # 查看可执行文件
nginx
[root@node1 sbin]# ./nginx # 启动nginx服务
  • 浏览器访问:http://虚拟机ip地址:nginx端口(80),本地主机浏览器访问需要关闭Linux防火墙
记得快乐
原文地址:https://www.cnblogs.com/Y-wee/p/14109371.html