生产场景:实战nginx源码编译安装

生产场景:nginx实战安装

一、准备环境:

1.1 操作系统:centos 6、7    

安装常用软件

yum install tree telnet dos2unix sysstat lrzsz nc nmap zip unzip -y

1.2 官网下载ngnx源码包nginx-1.12.2.tar.gz,并隐藏nginx版本号和修改nginx软件名

下载nginx源码包nginx-1.12.2.tar.gz,并隐藏nginx版本号和修改nginx软件名(此步骤省略)。

二、开始安装nginx

2.1 开始安装nginx并启动测试

####################快速安装nginx#############################mkdir /server/tools -pmkdir /applicationyum install openssl openssl-devel pcre pcre-devel -yuseradd www -s /sbin/nologin -Mcd /server/tools/rz -y  #上传优化好隐藏nginx版本号和修改nginx软件名字为Tengine的模板或者直接下载官网wget http://nginx.org/download/nginx-1.12.2.tar.gz,建议上传优化好的模板tar xf nginx-1.12.2.tar.gzcd nginx-1.12.2./configure --user=www --group=www --prefix=/application/nginx-1.12.2/ --with-http_stub_status_module --with-http_ssl_modulemakemake installln -s /application/nginx-1.12.2 /application/nginx

检查语法并启动nginx

/application/nginx/sbin/nginx -t 
/application/nginx/sbin/nginx
[[email protected] nginx-1.12.2]# ps -ef|grep nginx
root     25150     1  0 16:39 ?        00:00:00 nginx: master process /application/nginx-1.12.2 sbin/nginx
www      25151 25150  0 16:39 ?        00:00:00 nginx: worker process               
root     25164 16972  0 16:41 pts/0    00:00:00 grep nginx

浏览器打开web02 IP查看是否可以看到nginx主页:

http://10.0.0.8/

测试完成后关闭nginx服务。

/application/nginx/sbin/nginx -s stop

2.2 优化nginx配置文件

cd /application/nginx/conf/
cp nginx.conf{,.ori}
egrep -v "^$|#" nginx.conf.default >nginx.conf       #最小化nginx配置

查看默认配置文件

[[email protected] conf]# cat nginx.conf 
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

vim nginx.conf把server标签移除,并在http标签中加入include extra/www.conf;和include extra/status.conf;

[[email protected] conf]# vim nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include    extra/www.conf;
    include    extra/status.conf;
}

增加www.conf目录及配置文件

[[email protected] conf]# pwd
/application/nginx/conf
[[email protected] conf]# mkdir extra
[[email protected] extra]# vim extra/www.conf      #添加server标签,www1.etiantian.com用于监控www.etiantian.com是否正常
    server {
        listen       80;
        server_name  www.etiantian.com www1.etiantian.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
    }

增加status.conf目录及配置文件

原文地址:http://blog.51cto.com/sandshell/2157730

时间: 2024-08-01 11:08:08

生产场景:实战nginx源码编译安装的相关文章

实战Nginx源码编译安装与配置

实验环境:RHEL7.0    server1.example.com  172.25.254.1 实验内容:   1.准备                      2. 安装                      3.配置                      4.添加https                      5.虚拟主机                      6.<<nginx 监控小插件>>网站信息统计                      7.

Nginx 源码编译安装

Nginx 源码编译安装环境 Centos7 Nginx1.8.1    下载地址:http://nginx.org/download/ 选择自己想要的版本 我这边使用1.8.1,下载地址:http://nginx.org/download/nginx-1.8.1.tar.gz 1.编译前安装环境 [[email protected]_30 ~]# yum groupinstall "Development Tools" -y                #安装开发工具包 [[ema

Nginx源码编译安装选项

[Nginx源码编译过程] make是用来编译的,它从Makefile中读取指令,然后编译. make install是用来安装的,它也从Makefile中读取指令,安装到指定的位置. configure命令是用来检测你的安装平台的目标特征的.它定义了系统的各个方面,包括nginx的被允许使用的连接处理的方法,比如它会检测你是不是有CC或GCC,并不是需要CC或GCC,它是个shell脚本,执行结束时,它会创建一个Makefile文件. [Nginx的configure命令支持以下参数] --p

nginx 源码编译安装并编写服务启动脚本

1. 使用xshell将nginx源码包上传到server 2. 安装依赖的软件包工具 zlib-devel?? pcre-devel?? gcc? gcc-c++ yum -y install zlib-devel pcere-devel gcc gcc-c++ 验证一下: 3. 指定nginx的运行用户 (创建nginx用户不使其登录系统.-M不创建宿主目录) [[email protected] ~]# useradd -s /sbin/nologin -M nginx 4. 编译安装ng

ubuntu环境下nginx源码编译安装

1.更新系统 sudo apt-get update && sudo apt-get upgrade 2.安装nginx的依赖包  zlib pcre openssl(可以源码安装也可以直接系统安装) sudo apt-get install libpcre3 libpcre3-dev zlib1g-dev libssl-dev build-essential 3.下载openssl源码包 wget http://www.openssl.org/source/openssl-1.0.2a.

nginx源码编译安装

安装编译所需的包: [[email protected] ~]# yum install -y gcc gcc-c++ autoconf automake 安装nginx使用某些功能需要的包: [[email protected] ~]# yum install -y zlib zlib-devel openssl openssl-devel pcre-devel 创建用户: [[email protected] ~]# useradd -u 8000 -s /sbin/nologin ngin

Centos7通过yum跟源码编译安装Nginx

源码编译安装 http://nginx.org/en/download.html 到官网下载,然后用XFTP上传到root目录 把文件解压出来 tar -zxvf nginx-1.16.0.tar.gz 然后用yum安装依赖项 yum install gcc pcre-devel zlib-devel 如果没装以上相关的依赖,会在./configure过程中出现各种错误 下图是没装gcc包的错误,我看网上要装gcc-c++,但我发现我只安装gcc也没问题 下图是没装pcre-devel出现的错误

详解LAMP源码编译安装

实战:LAMP源码编译安装 家住海边喜欢浪:zhang789.blog.51cto.com 目录 详解LAMP源码编译安装 LAMP简介 一.准备工作 二.编译安装 Apache 三.编译安装 MySQL 四.编译安装 PHP 测试LAMP搭建开源数据web管理程序phpMyadmin 详解LAMP源码编译安装 LAMP简介 LAMP是当下非常流行的一套Web架构,我们可以在GNU/Linux下通过其他人打包的程序包来进行安装; 但是在生产环境中,很多时候都需要我们自己定制安装AMP,编译安装L

LNMP源码编译安装

系统环境为Centos6.5 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables  #编辑防火墙配置文件,将下面两条规则添加到22端口规则下面 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙) -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过