You've already forked www.colben.cn
update
This commit is contained in:
@@ -6,10 +6,10 @@ tags: ["nginx", "https", "ssl", "反向代理"]
|
||||
categories: ["web"]
|
||||
---
|
||||
|
||||
# set
|
||||
## set
|
||||
- set ${变量名} {字符串};
|
||||
|
||||
# 全局变量
|
||||
## 全局变量
|
||||
- $args $query_string 请求行中的参数
|
||||
- $content_length 请求头里的 Content-length 字段
|
||||
- $content_type 请求头里的 Content-type 字段
|
||||
@@ -31,7 +31,7 @@ categories: ["web"]
|
||||
- $request_uri 包含请求参数的原始URI,不包含主机名,如"/foo/bar.php?arg=baz"
|
||||
- $document_uri $uri 不带请求参数的当前URI,不包含主机名,如"/foo/bar.html"
|
||||
|
||||
# rewrite
|
||||
## rewrite
|
||||
- rewrite {url正则} {replacement} {flag};
|
||||
- flag
|
||||
- last 完成 rewrite,重新开始匹配
|
||||
@@ -39,7 +39,7 @@ categories: ["web"]
|
||||
- redirect 返回 302 临时重定向
|
||||
- permanent 返回 301 永久重定向
|
||||
|
||||
# if
|
||||
## if
|
||||
- if(condition){...}
|
||||
- false 字符串为空或以 0 开头都是
|
||||
- = != 变量比较
|
||||
@@ -50,19 +50,19 @@ categories: ["web"]
|
||||
- -e !-e 判断文件、目录、链接是否存在
|
||||
- -x !-x 判断可执行文件是否存在
|
||||
|
||||
# location
|
||||
## location
|
||||
- = 精确匹配
|
||||
- ^~ 开头匹配指定字符串,不是正则,匹配符合后停止搜索
|
||||
- ~ 区分大小写的正则匹配,匹配符合后继续向下搜索
|
||||
- ~`*` 不区分大小写的正则匹配,匹配符合后继续向下搜索
|
||||
- / 通用匹配,可匹配任何请求,匹配后继续向下搜索
|
||||
|
||||
# try_files
|
||||
## try_files
|
||||
- try_files {file} ... {uri}
|
||||
- try_files {file} ... ={code}
|
||||
- try_files {file} ... {location_name}
|
||||
|
||||
# 客户端访问控制
|
||||
## 客户端访问控制
|
||||
- deny all 拒绝全部访问
|
||||
- deny 192.168.1.0/24 拒绝指定网段
|
||||
- deny 192.168.1.2 拒绝指定ip
|
||||
@@ -70,7 +70,7 @@ categories: ["web"]
|
||||
- allow 192.168.1.0/24 允许指定网段
|
||||
- allow 192.168.1.2 允许指定ip
|
||||
|
||||
# 配置 web 访问目录
|
||||
## 配置 web 访问目录
|
||||
```bash
|
||||
location / {
|
||||
root /var/www/html/;
|
||||
@@ -79,7 +79,7 @@ location / {
|
||||
}
|
||||
```
|
||||
|
||||
# 下载
|
||||
## 下载
|
||||
```nginx
|
||||
location ^~ /attachment/ {
|
||||
root /data/;
|
||||
@@ -88,7 +88,7 @@ location ^~ /attachment/ {
|
||||
}
|
||||
```
|
||||
|
||||
# 浏览目录文件
|
||||
## 浏览目录文件
|
||||
```nginx
|
||||
location ^~ /share/ {
|
||||
autoindex on;
|
||||
@@ -97,7 +97,7 @@ location ^~ /share/ {
|
||||
}
|
||||
```
|
||||
|
||||
# 反向代理负载均衡
|
||||
## 反向代理负载均衡
|
||||
- /etc/nginx/conf.d/upstream.conf
|
||||
```nginx
|
||||
http {
|
||||
@@ -136,7 +136,7 @@ location ^~ /share/ {
|
||||
}
|
||||
```
|
||||
|
||||
# 反向代理 websocket
|
||||
## 反向代理 websocket
|
||||
```nginx
|
||||
location /websocket/ {
|
||||
proxy_pass http://127.0.0.1:8002;
|
||||
@@ -146,7 +146,7 @@ location /websocket/ {
|
||||
}
|
||||
```
|
||||
|
||||
# Basic HTTP 认证
|
||||
## Basic HTTP 认证
|
||||
- 生成密码文件(用户名是admin,密码是123456)
|
||||
```bash
|
||||
echo "admin:$(openssl passwd -crypt 123456)" > /etc/nginx/nginx.auth
|
||||
@@ -161,7 +161,7 @@ location /websocket/ {
|
||||
}
|
||||
```
|
||||
|
||||
# 创建 ssl 密钥
|
||||
## 创建 ssl 密钥
|
||||
```bash
|
||||
mkdir /etc/nginx/ssl && cd /etc/nginx/ssl
|
||||
openssl genrsa -out ssl.key 2048
|
||||
@@ -169,7 +169,7 @@ openssl req -new -key ssl.key -days 3650 -out ssl.csr
|
||||
openssl x509 -req -in ssl.csr -signkey ssl.key -out ssl.crt
|
||||
```
|
||||
|
||||
# https 访问
|
||||
## https 访问
|
||||
```nginx
|
||||
server {
|
||||
ssl on;
|
||||
@@ -184,7 +184,7 @@ server {
|
||||
}
|
||||
```
|
||||
|
||||
# http 自动跳转 https,有三种配置
|
||||
## http 自动跳转 https,有三种配置
|
||||
- rewrite 服务端重定向
|
||||
```nginx
|
||||
server {
|
||||
@@ -218,7 +218,7 @@ server {
|
||||
}
|
||||
```
|
||||
|
||||
# http 和 https 共存
|
||||
## http 和 https 共存
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
@@ -233,7 +233,7 @@ server {
|
||||
}
|
||||
```
|
||||
|
||||
# nginx 日志配置
|
||||
## nginx 日志配置
|
||||
- http 常规日志
|
||||
```
|
||||
log_format main '$remote_addr - [$time_local] "$request_method $uri" "$args" '
|
||||
@@ -259,7 +259,7 @@ server {
|
||||
'"$http_user_agent" "-"';
|
||||
```
|
||||
|
||||
# 常用全局配置
|
||||
## 常用全局配置
|
||||
```nginx
|
||||
events {
|
||||
use epoll;
|
||||
|
Reference in New Issue
Block a user