linux安装LNMP环境之安装nginx

简介: 安装nginx确保没有安装扩展 yum install wget gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel然后:cd /usr/local/src/wget http://nginx.

安装nginx

确保没有安装扩展
 yum install wget gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel

然后:

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.12.2.tar.gz

下载完成之后解压:

tar zxvf nginx-1.12.2.tar.gz

预编译:

[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_dav_module   --with-http_addition_module  --with-http_sub_module --with-http_flv_module  --with-http_mp4_module

解释:

--with-http_gzip_static_module :支持压缩
--with-http_stub_status_module :支持nginx状态查询
--with-http_ssl_module :支持https
--with-pcre :为了支持rewrite重写功能,必须制定pcre
--with-http_dav_module #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)
--with-http_addition_module #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)

编译:

make && make install 

添加系统变量(方便启停服务)

vim /etc/profile

第56行添加

export PATH=/usr/local/nginx/sbin:$PATH

然后重新启动

source /etc/profile

添加软连接

 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

服务器启动脚本:

vim /etc/init.d/nginx

把下面内容放进去

#!/bin/bash
# chkconfig: - 99 2
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
        start)
        $PROG
        ;;
        stop)
        kill -3 $(cat $PIDF)
        ;;
        restart)
        $0 stop &> /dev/null
        if [ $? -ne 0 ] ; then continue ; fi
        $0 start
        ;;
        reload)
        kill -1 $(cat $PIDF)
        ;;
        *)
        echo "Userage: $0 { start | stop | restart | reload }"
        exit 1
esac
exit 0

配置服务开机自动启动

[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on

配置完了可以用一下命令控制nginx状态:

service nginx restart
service nginx start
service nginx stop

打开浏览器输入你的ip就可以看到welcome to nginx!

相关文章
|
4天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
42 1
|
14天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
73 0
|
14天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
34 0
|
14天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
17 0
|
14天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
47 0
|
16天前
|
运维 应用服务中间件 Linux
LNMP详解(十三)——Nginx子页面详解
LNMP详解(十三)——Nginx子页面详解
14 3
|
22天前
|
运维 负载均衡 应用服务中间件
LNMP详解(九)——Nginx虚拟IP实战
LNMP详解(九)——Nginx虚拟IP实战
34 2
|
17小时前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
9 2
|
1天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
3 0
|
1天前
|
Ubuntu Linux 开发工具
WSL2(3)安装Linux headers完美解决方案
WSL2(3)安装Linux headers完美解决方案
3 0