linux上Nginx源码安装

一、nginx源码安装

0、准备工作

对于nginx的启用要关闭、禁用防火墙、同步时钟

[root@nginx1 ~] systemctl stop firewalld#停止防火请
[root@nginx1 ~] systemctl disable firewalld#禁用防火墙
[root@nginx1 ~] sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config#将selinux禁用
[root@nginx1 ~] setenforce 0#临时关闭selinux
[root@nginx1 ~] yum -y install ntp ntpdate#下载同步时钟的软件
[root@nginx1 ~] ntpdate cn.pool.ntp.org#同步
[root@nginx1 ~] hwclock --systohc#将硬件时间同步为系统时间

1、安装依赖包

对于源码包需要编译预编译等所需要的软件也挺多,可以用yum一下安装

 [root@nginx1 ~]yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2、创建nginx的安装目录

[root@nginx1 ~] cd /usr/local
[root@nginx1 ~] mkdir nginx
[root@nginx1 ~]cd nginx/

3、下载安装包并解压

[root@nginx1 ~] wget https://nginx.org/download/nginx-1.16.1.tar.gz# 比如这个版本
https://nginx.org/download/#可以在这个链接里面找要下载的版本
[root@nginx1 ~] tar -xzvf nginx-1.16.1.tar.gz #解压

4、预编译和编译

[root@nginx1 ~] cd nginx-1.16.1# 进入到解压好的目录下
[root@nginx1 ~] ./configure --prefix=/usr/local/nginx #预编译 
[root@nginx1 ~] make && make install #编译

5、修改nginx的访问界面

[root@nginx1 ~] cd /usr/local/nginx/html/
[root@nginx1 html] vi index.html #进入编辑

6、启动服务并测试

[root@nginx1 html] /usr/local/nginx/sbin/nginx# 启动
[root@nginx1 html]/usr/local/nginx/sbin/nginx -s stop #关闭nginx服务

测试:在地址栏输入IP地址会跳转到你编写的页面
在这里插入图片描述

Guess you like

Origin blog.csdn.net/qq_46495338/article/details/114457315