编译安装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 ...
随机推荐
- 攻防世界 WEB 高手进阶区 PHP2 Writeup
攻防世界 WEB 高手进阶区 PHP2 Writeup 题目介绍 题目考点 url 二次解码 index.phps 文件(第一次使用dirsearch可能扫不到,需要加到工具字典里) php 简单语法 ...
- mysql 免密码登录
mysql 8免密码登录 UPDATE mysql.user SET authentication_string=null WHERE User='root'; FLUSH PRIVILEGES; e ...
- 本地以sysdba 身份登录数据库实例时,报错ORA-01031 权限不足
在linux 操作系统的数据库服务器上,使用"sqlplus / as sysdba" 登录Oracle 10.2 数据库实例时,登录失败,显示ORA-01031: 权限不足. ...
- 【Microsoft Azure 的1024种玩法】四. 利用Azure Virtual machines 打造个人专属云盘,速度吊打某云盘
[简介] 1.Azure Virtual machines是Azure 提供的多种可缩放按需分配计算资源之一,Nextcloud是一款开源免费的私有云存储网盘项目,可以让你快速便捷地搭建一套属于自己或 ...
- [cf1340D]Nastya and Time Machine
记$deg_{i}$为$i$的度数,简单分类讨论可得答案下限为$\max_{i=1}^{n}deg_{i}$ 另一方面,此下限是可以取到的,构造方法较多,这里给一个巧妙一些的做法-- 对其以dfs(儿 ...
- [cf1168E]Xor Permutations
(与题目中下标不同,这里令下标为$[0,2^{k})$来方便运算) 根据异或的性质,显然有解的必要条件是$\bigoplus_{i=0}^{2^{k}-1}a_{i}=0$ 在此基础上,我们考虑构造- ...
- [noi253]A
定义f[i][j]表示从(i,j)走到最后一行的期望,不断从下往上dp那么对于每一行都可以得到m个方程. 但由于这m个方程不是DAG,因此考虑用高斯消元,但时间复杂度不对. 观察方程可以发现如果不断将 ...
- nginx得请求转发代码-将请求转发到网关
首先:本地主机host更改成 192.168.111.1 gulimail.com 这样一访问网址就能映射到本地. 然后修改nginx得conf worker_processes 1; events ...
- watch异步操作
异步操作: 1.ajax, 2.定时器 3.点击事件 4.数据库操作 特点:代码不等待,后续代码会继续执行. watch:{ //watch作用监测已经存在的数据 newVal 新值,oldVal 旧 ...
- sar 系统活动情况报告
sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告, 包括:文件的读写情况.系统调用的使用 ...