编译安装nginx 1.16
准备源码包,并解压,创建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的更多相关文章
- 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 ...
- 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 查看硬 ...
- 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 查看硬 ...
- CentOS6.6 32位 Minimal版本纯编译安装Nginx Mysql PHP Memcached
声明:部分编译指令在博客编辑器里好像被处理了,如双横线变成单横线了等等,于是在本地生成了一个pdf版本,在下面地址可以下载. LNMP+Memcached CentOS是红帽发行的免费的稳定Linux ...
- 初识Nginx及编译安装Nginx
初识Nginx及编译安装Nginx 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 nginx-1.12.2 1.什么是Nginx? 如果你听说或使用过Apache软件 ...
- Centos7 编译安装 Nginx、MariaDB、PHP
前言 本文主要大致介绍CentOS 7下编译安装Nginx.MariaDB.PHP.面向有Linux基础且爱好钻研的朋友.技艺不精,疏漏再所难免,还望指正. 环境简介: 系统: CentOS 7,最小 ...
- Ubuntu编译安装nginx以及配置自动启动
本文主要介绍ubuntu如何编译安装nginx以及遇到的问题 和 配置系统自动启动服务 查看操作系统版本 cat /etc/issue Ubuntu 18.04.3 LTS \n \l 更改镜 ...
- Centos7编译安装Nginx+keepalived
一.安装环境.主机信息及软件版本 Nginx:1.12.2keepalived:2.0.12时间同步(同步后确认各服务器时间是否一致,不一致需要修改一下时区) 关闭防火墙 二.编译安装Nginx 1. ...
- linux服务基础之编译安装nginx
nginx源码下载地址: http://nginx.org/download/nginx-1.16.0.tar.gz //根据需要下载其他版本 1. 下载nginx # wget http://ngi ...
随机推荐
- Linux下安装、配置、启动与访问RabbitMQ
一.下载 首先第一步要下载三个rpm安装包,为了方便安装与学习,给出下载途径 网盘网址:https://pan.baidu.com/s/18Z64Lb9KQpRh10RzqZBdoQ 提取码:094v ...
- PTA 7-2 邻接表创建无向图 (20分)
PTA 7-2 邻接表创建无向图 (20分) 采用邻接表创建无向图G ,依次输出各顶点的度. 输入格式: 输入第一行中给出2个整数i(0<i≤10),j(j≥0),分别为图G的顶点数和边数. 输 ...
- OpenXml SDK学习笔记(4):设置文件级别的样式
观察上一段日记最后的代码: 这里的样式基本可以理解为行内CSS.那么既然有行内的样式,就肯定有外部的样式.那这部分就对应笔记1里说的style.xml文件.这个文件对应的是Document.MainD ...
- Are we ready for learned cardinality estimation?
Are we ready for learned Cardinality Estimation 摘要 文章包括三大部分: 对于一个静态的数据库,本文将五种基于学习的基数估计方法与九中传统的基数估计方法 ...
- Java学习(二十二)
学了一个在css中叫font的样式: 感觉还是挺好用的 不过要注意如果把font放在最后,其他会使用默认值,可能会覆盖掉前面的 例如新学的行高 在font中语法是 font:30px/40px &qu ...
- dotNET5的MVC页面传值方式总结
本文大致讲解mvc前后端的传值方式,包括control向view.view向control.以及action向action. 一.经典回顾 二.Controller向View传值 1. ViewBag ...
- python一对一教程:Computational Problems for Physics chapter 1 Code Listings
作者自我介绍:大爽歌, b站小UP主 ,直播编程+红警三 ,python1对1辅导老师 . 本博客为一对一辅导学生python代码的教案, 获得学生允许公开. 具体辅导内容为<Computati ...
- Go语言核心36讲(Go语言实战与应用八)--学习笔记
30 | 原子操作(下) 我们接着上一篇文章的内容继续聊,上一篇我们提到了,sync/atomic包中的函数可以做的原子操作有:加法(add).比较并交换(compare and swap,简称 CA ...
- C++getline()
#include <iostream>#include <cstring>#include <string>using namespace std;int main ...
- 推荐一款颜值逆天且功能齐全的开源Shell工具!
前言 以前在windows上一直使用的SSH工具是XShell,后来转到mac平台,XShell没有mac版本.所以之前一直在找一款颜值高,功能齐全的可以作为日常使用的Shell工具. 我知道mac下 ...