准备源码包,并解压,创建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. dart系列之:dart语言中的函数

    目录 简介 函数的参数 main函数 匿名函数 闭包 函数的返回值 总结 简介 函数是所有编程语言都有的内容,不管是面向对象还是面向过程,函数都是非常重要的一部分.dart中的函数和java中的函数有 ...

  2. cwRsync 实现两台服务器Windows Server 2012 R2间的文件同步(备份)

    sync下载链接:https://pan.baidu.com/s/1aZeGDA5bU9f1h6nxvVJsDw  提取码:jtv3 1.配置IP地址 Server端:192.167.1.2(自定义) ...

  3. 注解@RunWith的作用

    @RunWith就是一个运行器 @RunWith(JUnit4.class)就是指用JUnit4来运行 @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Sp ...

  4. 设计模式学习-使用go实现适配器模式

    适配器模式 定义 代码实现 优点 缺点 适用范围 代理.桥接.装饰器.适配器4种设计模式的区别 参考 适配器模式 定义 适配器模式的英文翻译是Adapter Design Pattern.顾名思义,这 ...

  5. 中文NER的那些事儿5. Transformer相对位置编码&TENER代码实现

    这一章我们主要关注transformer在序列标注任务上的应用,作为2017年后最热的模型结构之一,在序列标注任务上原生transformer的表现并不尽如人意,效果比bilstm还要差不少,这背后有 ...

  6. [bzoj2245]工作安排

    由于价格是单调递增的,因此可以直接建立Si条边,流量和价格依次为给定的函数即可(如果价格不递增,可以考虑动态加边等操作) 1 #include<bits/stdc++.h> 2 using ...

  7. Java ArrayList小记

    1.基本用法 ArrayList是一个泛型容器,新建ArrayList需要实例化泛型参数,比如: ArrayList<String> StrList = new ArrayList< ...

  8. vue项目中使用canvas

    canvas API 文档:https://www.canvasapi.cn/ 一.在html中使用canvas canvas 元素用于在网页上绘制图形.  在html中,使用 document.ge ...

  9. Codeforces 295D - Greg and Caves(dp)

    题意: 给出一个 \(n \times m\) 的矩阵,需对其进行黑白染色,使得以下条件成立: 存在区间 \([l,r]\)(\(1\leq l\leq r\leq n\)),使得第 \(l,l+1, ...

  10. bitset 的妙用:乱搞字符串匹配

    最近碰到了几次 bitset 乱搞字符串匹配的情况,故写文以记之. 1. 算法简介 核心思想:假设文本串为 \(s\),则对字符集中的每一个字符 \(c\) 开一个大小为 \(|s|\) 的 bits ...