惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
腾讯CDC
T
Tailwind CSS Blog
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
The Cloudflare Blog
D
DataBreaches.Net
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta
B
Blog
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19)
Nginx 配置问题记录
微信公众号 · 2018-04-18 · via 陈少文的网站

1. server_name 无效

现象:Nginx 反向代理了两个应用,配置详情如下。发现访问 b.chenshaowen.coma.chenshaowen.com 时,返回的都是 A 服务的请求。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
server {

	 listen 80;
	 server_name a.chenshaowen.com;
	 location / {
			proxy_pass http://A;
	 }
 }

server {

	listen 8080;
	server_name b.chenshaowen.com;
	location / {
		   proxy_pass http://B;
	}
}

原因:当所有 server 的规则都不匹配时,Nginx 会采用第一条 server 配置。

解决办法:在最前处,新增一条 server

1
2
3
4
5
6
server {
	  listen 80;
	  server_name XX.chenshaowen.com;
	  return 404;
 }
 # 其他 server

2. Nginx 增加密码验证

1.安装密码生成工具

1
yum install httpd-tools

2.生成账号密码

1
htpasswd -bc /your/password/file/path username password

3.Nginx 配置

1
2
3
4
5
location / {
	   auth_basic "input password";
	   auth_basic_user_file  /your/password/file/path;
	   ...
 }

4.重启 Nginx 服务

1
2
3
4
nginx -s reload
```

当再次访问时,Nginx 会弹出一个小框,提示输入密码。使用 username:password 即可登录、