一、 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 (一)的更多相关文章

  1. Nginx 代理以及HTTPS (二)

    一.HTTPS解析 https 加密 私钥 公钥 http 的握手 是确认网络是连通的. https 的握手 是一个加密的过程 加密图 二. 使用Nginx 部署HTTPS 服务 1.证书生成命令(h ...

  2. nginx代理https站点(亲测)

    nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...

  3. nginx 代理 https 后,应用变成 http

    需求:nginx 代理 https,后面的 tomcat 处理 http 请求,sso 的客户端,重定向时需要带上 target,而这个 target 默认是 tomcat 的 http,现在需要把这 ...

  4. 使用nginx代理后以及配置https后,如何获取真实的ip地址

    使用nginx代理后以及配置https后,如何获取真实的ip地址 Date:2018-8-27 14:15:51 使用nginx, apache等反向代理后,如果想获取请求的真实ip,要在nginx中 ...

  5. CentOS 7.X下 -- 配置nginx正向代理支持https

    环境说明: 本次测试使用的操作系统为:CentOS 7.2 x86 64位 最小化安装的操作系统,系统基础优化请参考:https://www.cnblogs.com/hei-ma/p/9506623. ...

  6. NGINX之——配置HTTPS加密反向代理訪问–自签CA

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46695495 出于公司内部訪问考虑,採用的CA是本机Openssl自签名生成的,因 ...

  7. nginx 代理https后,应用redirect https变成http --转

    原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...

  8. nginx 反向代理及 https 证书配置

    nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...

  9. 单机部署minio,设置Nginx代理,配置https(TLS)访问

    安装 下载地址:https://dl.min.io/ # 创建目录 mkdir -p /usr/local/minio/{data,bin,etc} # 下载minio wget https://dl ...

随机推荐

  1. docker下修改mysql配置文件

    原文:docker下修改mysql配置文件 版权声明:本文为博主原创文章,转载注明地址:http://blog.csdn.net/wang704987562 https://blog.csdn.net ...

  2. Linux头文件的设置

    GCC/G++会查找系统默认的include和link的路径,以及自己在编译命令中指定的路径. 1.include头文件路径 除了默认的/usr/include, /usr/local/include ...

  3. HDU——T 2444 The Accomodation of Students

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others)    Memory Limi ...

  4. mysql中文乱码解决方式

    近期项目使用到mysql.却突然出现了中文乱码问题.尝试了多种方案,最终解决乱码问题,总结一下解决方式,给遇到同样问题的人一点參考. 中文乱码的原因 1.安装mysqlserver的时候编码集设定有问 ...

  5. Leetcode--easy系列9

    #198 House Robber You are a professional robber planning to rob houses along a street. Each house ha ...

  6. linux清除邮件队列

    [root@localhost mail]#tmp=`mailq | grep -E "root" | awk '{print $1}'` [root@localhost mail ...

  7. Linux-php安装mongodb

    Linux-php安装mongodb 标签(空格分隔): php 安装mongodb 1 下载解压 下载压缩包 :https://www.mongodb.com/download-center?jmp ...

  8. POJ 3662 二分+Dijkstra

    题意: 思路: 二分+Disjktra 二分一个值 如果某条边的边权比它小,则连上边权为0的边,否则连上边权为1的边 最后的d[n]就是最小要免费连接多少电话线. //By SiriusRen #in ...

  9. java9新特性-5-Java的REPL工具: jShell命令

    1.官方Feature 222: jshell: The Java Shell (Read-Eval-Print Loop) 2.产生背景 像Python 和 Scala 之类的语言早就有交互式编程环 ...

  10. AngularJs轻松入门(九)与服务器交互

    AngularJs从Web服务器请求资源都是通过Ajax来完成,所有的操作封装在$http服务中,$http服务是只能接收一个参数的函数,这个参数是一个对象,用来完成HTTP请求的一些配置,函数返回一 ...