NGINX 代理以及 HTTPS (一)
一、 Nginx 安装 和基础代理配置

假如 启动nginx 出现这个错误,可能是 iis服务被打开了,80端口被占用了。

需要如下操作:

用Nginx 配置一个test.com 的代理名称。配置host 分配服务器。



二、 Nginx 代理配置和代理缓存的用处




server.js 代码:
const http = require('http')
const fs = require('fs')
const wait = (seconds) => {
return new Promise((resolve) => {
setTimeout(resolve, seconds * )
})
}
http.createServer(function (request, response) {
console.log('request come', request.url)
if (request.url === '/') {
const html = fs.readFileSync('test.html', 'utf8')
response.writeHead(, {
'Content-Type': 'text/html'
})
response.end(html)
}
if (request.url === '/data') {
response.writeHead(, {
'Cache-Control': 'max-age=5, s-maxage=20, private', //s-maxage=20 代理服务器的缓存时间(优先) private 不允许使用代理服务器缓存可以使用浏览器缓存
'Vary': 'X-Test-Cache' //验证头信息是否一样,一样就用缓存,不一样不用缓存
})
wait().then(() => response.end('success'))
}
}).listen()
console.log('server listening on 8888')
test.html 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>This is content, and data is: <span id="data"></span></div>
<button id="button">click me</button>
</body>
<script>
var index =
function doRequest () {
var data = document.getElementById('data')
data.innerText = ''
fetch('/data', {
headers: {
'X-Test-Cache': index++
}
}).then(function (resp) {
return resp.text()
}).then(function (text) {
data.innerText = text
})
}
document.getElementById('button').addEventListener('click', doRequest)
</script>
</html>
Nginx 配置代码:
proxy_cache_path cache levels=: keys_zone=my_cache:10m; //配置缓存的路径 以及缓存文件的存储形式 以及最大的缓存值。
server {
listen ;
server_name test.com;
location / {
proxy_cache my_cache;
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
}
}
server {
listen ;
server_name a.test.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host;
}
}
NGINX 代理以及 HTTPS (一)的更多相关文章
- Nginx 代理以及HTTPS (二)
一.HTTPS解析 https 加密 私钥 公钥 http 的握手 是确认网络是连通的. https 的握手 是一个加密的过程 加密图 二. 使用Nginx 部署HTTPS 服务 1.证书生成命令(h ...
- nginx代理https站点(亲测)
nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...
- nginx 代理 https 后,应用变成 http
需求:nginx 代理 https,后面的 tomcat 处理 http 请求,sso 的客户端,重定向时需要带上 target,而这个 target 默认是 tomcat 的 http,现在需要把这 ...
- 使用nginx代理后以及配置https后,如何获取真实的ip地址
使用nginx代理后以及配置https后,如何获取真实的ip地址 Date:2018-8-27 14:15:51 使用nginx, apache等反向代理后,如果想获取请求的真实ip,要在nginx中 ...
- CentOS 7.X下 -- 配置nginx正向代理支持https
环境说明: 本次测试使用的操作系统为:CentOS 7.2 x86 64位 最小化安装的操作系统,系统基础优化请参考:https://www.cnblogs.com/hei-ma/p/9506623. ...
- NGINX之——配置HTTPS加密反向代理訪问–自签CA
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46695495 出于公司内部訪问考虑,採用的CA是本机Openssl自签名生成的,因 ...
- nginx 代理https后,应用redirect https变成http --转
原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...
- nginx 反向代理及 https 证书配置
nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...
- 单机部署minio,设置Nginx代理,配置https(TLS)访问
安装 下载地址:https://dl.min.io/ # 创建目录 mkdir -p /usr/local/minio/{data,bin,etc} # 下载minio wget https://dl ...
随机推荐
- thymeleaf 拼接 超链接
<dd><a th:href="@{/get/{id}(id=${user.id})}">基本资料</a></dd>
- 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence
Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- POJ 1161 Walls(最短路+枚举)
POJ 1161 Walls(最短路+枚举) 题目背景 题目大意:题意是说有 n个小镇,他们两两之间可能存在一些墙(不是每两个都有),把整个二维平面分成多个区域,当然这些区域都是一些封闭的多边形(除了 ...
- 洛谷 P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
- word break相关问题的解法
https://leetcode.com/problems/word-break/?tab=Description 以及 https://leetcode.com/problems/concatena ...
- android将String转化为MD5的方法+一些String经常使用的方法
public class StringUtils { public static String MD5Encode(String origin) { String resultString = nul ...
- [Mobx] Using mobx to isolate a React component state
React is great for diffing between Virtual-DOM and rendering it to the dom. It also offers a naïve s ...
- nj05---模块
概念:模块(Module)和包(Package)是Node.js最重要的支柱.在浏览器JavaScript中,脚本模块的拆分和组合通常使用HTML的script标签来实现,Node.js提供了requ ...
- poj_2828线段树,逆序插入
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...
- Most common words
To find the most common words, we can apply the DSU pattern; most_common takes a histogram and retur ...