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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
博客园 - 司徒正美
J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
D
Docker
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
I
InfoQ
雷峰网
雷峰网
The Cloudflare Blog
美团技术团队
Engineering at Meta
Engineering at Meta

博客园 - 白马黑衣

网络安全3 - Easy RSA重新签发客户端证书 RHEL - 笔记本合盖不休眠 RHEL - yum cache JFrog Artifactory 系列6 --- 其他配置 Node.js - 配置npm Rocky Linux 升级失败 Linux --- firewalld 2 - nfttables Linux - DNS Apache HTTP Server 关闭SELinux RHEL - 设置hostname和IP地址 Linux --- 查看PID 判断端口是否已经被占用 Maven 常用命令 Jenkins 系列3 --- pipeline Git自签名证书的验证 iptables Jenkins 系列2 --- Node/Agent Jenkins 系列1 --- 安装与配置
Nginx 系列2 --- 配置
白马黑衣 · 2023-12-16 · via 博客园 - 白马黑衣

一、概要

1. 承上启下

(1) Nginx 系列

二、配置

1. 测试配置

2. nginx配置文件

(1) 配置文件

sudo vi /etc/nginx/nginx.conf

(2) 关键配置

events {
  worker_connections  4096;  ## Default: 1024
}
http {
  server {
    listen 80;
    listen [::]:80;
    server_name localhost;
    location / {
      root /etc/nginx/html;
      index index.html index.htm;
    }
  }
}

a. listen: 是nginx需要监听的端口号;

b. server_name: 是nginx代理的域名,如果配置成.example.com,则example.com所有子域名都会被命中;

c. location: 存储路径信息,这里root指http网站的根目录:

请求http://www.example.com/,返回页面对应的目录是/etc/nginx/html/index.html。

3. 子配置文件

(1) 按需创建

sudo vi /etc/nginx/conf.d/http
sudo vi /etc/nginx/conf.d/stream
sudo vi /etc/nginx/conf.d/mail
sudo vi /etc/nginx/conf.d/exchange-enhanced

a. Events: 一般链接处理;

b. Http: Http模块;

c. Mail: 邮件模块;

d. Stream: TCP和UDP流量。

(2) 在/etc/nginx/nginx.conf中按需添加引用

include /etc/nginx/conf.d/http/*.conf;
include /etc/nginx/conf.d/stream/*.conf;
include /etc/nginx/conf.d/exchange-enhanced/*.conf;

4. 配置证书

(1) Letscrypt证书

参考Letscrypt

(2) SELinux

使用自签发证书时,如果服务器开启了SELinux可能会出现Nginx无法加载证书文件的问题,此时需要运行以下命令解决:

sudo restorecon -v -R /etc/nginx/ssl

注意,/etc/nginx/ssl是证书所在的目录。

三、参考

1. 官方

http://nginx.org/en/docs/

http://nginx.org/en/docs/ngx_core_module.html

http://nginx.org/en/docs/http/ngx_http_core_module.html

http://nginx.org/en/docs/http/ngx_http_charset_module.html

http://nginx.org/en/docs/http/ngx_http_log_module.html

http://nginx.org/en/docs/mail/ngx_mail_ssl_module.html

http://nginx.org/en/docs/http/ngx_http_index_module.html

2. 其他

https://www.digitalocean.com/community/tools/nginx