准备源码包,并解压,创建nginx用户

[root@slave-master ~]# tar xf nginx-1.16.0.tar.gz
[root@slave-master ~]# useradd -r -s /sbin/nologin nginx
[root@slave-master ~]# cd nginx-1.16.0

准备开发包组

[root@slave-master nginx-1.16.0]# yum install gcc pcre-devel openssl-devel zlib-devel -y

开始编译安装

[root@slave-master nginx-1.16.0]# ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@slave-master nginx-1.16.0]# make -j 4 && make install

修改路径并启动

[root@slave-master nginx-1.16.0]# cd /apps/nginx/
[root@slave-master sbin]# ln -sv /apps/nginx/sbin/* /usr/sbin
[root@slave-master sbin]# nginx

基于basic认证,先修改主配置文件,让它包含一个目录,我们就可以单独写配置文件

[root@slave-master src]# vim /apps/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
include /apps/nginx/conf/src/*.conf; [root@slave-master src]# mkdir /apps/nginx/conf/src/
[root@slave-master src]# vim /apps/nginx/conf/src/nginx.conf
server {
        server_name www.magedu.com;
        location / {
        root /apps/nginx/conf/src/html;
        auth_basic "renzheng";
        auth_basic_user_file "/apps/nginx/conf/src/.nginx";
        }
}

利用htpasswd命令创建用户

[root@slave-master src]# htpasswd -c /apps/nginx/conf/src/.nginx bob
New password:
Re-type new password:

测试

实现status页面

server {
server_name www.magedu.com;
access_log /apps/nginx/conf/src/access.log main;
location / {
root /apps/nginx/conf/src/html;
auth_basic "renzheng";
auth_basic_user_file "/apps/nginx/conf/src/.nginx";
}
location = /nginx_status {
stub_status;
allow 127.0.0.1;
deny all;
}
}

基于JSON格式的访问日志

[root@slave-master src]# vim nginx.conf
log_format access_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"uri":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"tcp_xff":"$proxy_protocol_addr",'
'"http_user_agent":"$http_user_agent",'
'"status":"$status"}'; server {
server_name www.magedu.com;
access_log /apps/nginx/conf/src/access.log main;
location / {
root /apps/nginx/conf/src/html;
auth_basic "renzheng";
auth_basic_user_file "/apps/nginx/conf/src/.nginx";
access_log /apps/nginx/conf/src/access_json.log access_json;

启用压缩功能

[root@slave-master messge]# vim ../nginx.conf
location /messge {
root /apps/nginx/conf/src;
gzip on;
gzip_comp_level 6;
gzip_min_length 64;
gzip_vary on;
gzip_types text/xml text/css application/javascript;
}

如果客户请求的页面不存在将自动跳转至首页

[root@slave-master messge]# vim ../nginx.conf 

        if (!-f $request_filename) {
rewrite (.*) http://www.magedu.com/index.html;
}

ssl

[root@slave-master ssl]# vim ../nginx.conf
server {
listen 443 ssl;
server_name wwww.magedu.com;
ssl_certificate "/apps/nginx/conf/src/ssl/magedu.com.crt";
ssl_certificate_key "/apps/nginx/conf/src/ssl/magedu.com.key";
root "/apps/nginx/conf/src/jiami";
}

将http请求跳转至https


[root@slave-master ssl]# vim ../nginx.conf
if ($scheme = http) {
rewrite / https://www.magedu.com/ redirect;
}

防盗链

[root@slave-master ssl]# vim ../nginx.conf
valid_referers none blocked server_names *.magedu.com magedu.* www.magedu.org/galleries/ ~\.google\.; if ($invalid_referer) {
return 403 "Forbidden Access";
}

配置文件下载

[root@slave-master src]# vim nginx.conf
location /download {
root /apps/nginx/conf/src;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
limit_rate 100k;
}
autoindex on | off;
自动文件索引功能,默为off
autoindex_exact_size on | off;
计算文件确切大小(单位bytes),off 显示大概大小(单位K、M),默认on
autoindex_localtime on | off ;
显示本机时间而非GMT(格林威治)时间,默认off
autoindex_format html | xml | json | jsonp;
显示索引的页面文件风格,默认html

编译安装nginx 1.16的更多相关文章

  1. Ubuntu 16.04源码编译安装nginx 1.10.0

    一.下载相关的依赖库 pcre 下载地址 http://120.52.73.43/jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.t ...

  2. Centos7 编译安装 Nginx Mariadb Asp.net Core2 (实测 笔记 Centos 7.3 + Openssl 1.1.0h + Mariadb 10.3.7 + Nginx 1.14.0 + Asp.net. Core 2 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...

  3. Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Openssl 1.1.0e + Mariadb 10.1.22 + Nginx 1.12.0 + PHP 7.1.4 + Laravel 5.4 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...

  4. CentOS6.6 32位 Minimal版本纯编译安装Nginx Mysql PHP Memcached

    声明:部分编译指令在博客编辑器里好像被处理了,如双横线变成单横线了等等,于是在本地生成了一个pdf版本,在下面地址可以下载. LNMP+Memcached CentOS是红帽发行的免费的稳定Linux ...

  5. 初识Nginx及编译安装Nginx

    初识Nginx及编译安装Nginx 环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    nginx-1.12.2 1.什么是Nginx? 如果你听说或使用过Apache软件 ...

  6. Centos7 编译安装 Nginx、MariaDB、PHP

    前言 本文主要大致介绍CentOS 7下编译安装Nginx.MariaDB.PHP.面向有Linux基础且爱好钻研的朋友.技艺不精,疏漏再所难免,还望指正. 环境简介: 系统: CentOS 7,最小 ...

  7. Ubuntu编译安装nginx以及配置自动启动

    本文主要介绍ubuntu如何编译安装nginx以及遇到的问题 和 配置系统自动启动服务 查看操作系统版本 cat /etc/issue  Ubuntu 18.04.3 LTS \n \l    更改镜 ...

  8. Centos7编译安装Nginx+keepalived

    一.安装环境.主机信息及软件版本 Nginx:1.12.2keepalived:2.0.12时间同步(同步后确认各服务器时间是否一致,不一致需要修改一下时区) 关闭防火墙 二.编译安装Nginx 1. ...

  9. linux服务基础之编译安装nginx

    nginx源码下载地址: http://nginx.org/download/nginx-1.16.0.tar.gz //根据需要下载其他版本 1. 下载nginx # wget http://ngi ...

随机推荐

  1. PCB各层介绍

    在PCB设计中用得比较多的图层: mechanical 机械层 keepout layer 禁止布线层 Signal layer 信号层 Internal plane layer 内部电源/接地层 t ...

  2. java eclipse调试提示Source not found 或 一闪而过 解决方法

    Web工程Eclipse  debug方式启动,在断点的位置被成功拦截,但是没有跳转到工程的代码处,提示如下: 当然这个时候如果我继续按F5的话呢,程序又会接着正常运行了.到这里那就是说程序本身是没有 ...

  3. MAC电脑如何将常规视频中音频提取出来(转换格式并调整采样频率),并利用讯飞语音识别文字

    1.下载好相关视频 2.选中需要提取视频,鼠标右键找到「编码所选视频文件」 3.设置中,下拉选择「仅音频」,点击继续 4.找到已提取成功的音频,鼠标右键或快捷键「command + I」,显示简介.默 ...

  4. java 邮件 接收与发送

    ... package com.e6soft; import java.io.BufferedReader; import java.io.FileOutputStream; import java. ...

  5. [atARC121E]Directed Tree

    令$b_{a_{i}}=i$,那么问题即要求$i$不是$b_{i}$的祖先,也即$b_{i}$不严格在$i$的子树中 显然$a_{i}$和$b_{i}$一一对应,因此我们不妨统计$b_{i}$的个数 ...

  6. [bzoj1178]会议中心

    考虑用f[i][j]表示以i为起点(i是时间,所以要离散)选$2^j$条线段(这里不是时间)最小的终点,预处理用倍增的方式来求即可预处理出这个数组后,就可以很快的求出在$[l,r]$的时间内最多能选多 ...

  7. 流程图(flowchart)语法学习

    创建流程图需要选择语言: mermaid流程中的代码包裹graph 这里写顺序end流程图方向:从上到下(TB),从下到上(BT),从左到右(LR),从右到左(RL) TB - 从上到下TD - 自上 ...

  8. CSS Web Fonts 网络字体

    Fonts 1. CSS font-family 在 CSS 中,可以使用 font-family 属性来指定字体,浏览器渲染文字时候会根据这个属性应用于元素.如果没有指定这个属性或者指定的字体不存在 ...

  9. CF1418G Three Occurrences

    统计满足某些性质的区间个数. 我们考虑移动 \(r\) 指针. 然后考虑把不能选的区间 \(ban\)掉. 具体看下细节吧. #include<iostream> #include< ...

  10. R语言矩阵相关性计算及其可视化?

    目录 1. 矩阵相关性计算方法 base::cor/cor.test psych::corr.test Hmisc::rcorr 其他工具 2. 相关性矩阵转化为两两相关 3. 可视化 corrplo ...