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

推荐订阅源

Vercel News
Vercel News
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
N
News | PayPal Newsroom
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
博客园 - Franky
SecWiki News
SecWiki News
Recent Announcements
Recent Announcements
T
Troy Hunt's Blog
The Register - Security
The Register - Security
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
S
Security Affairs
博客园 - 司徒正美
S
Schneier on Security
I
InfoQ
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threat Research - Cisco Blogs
Forbes - Security
Forbes - Security
腾讯CDC
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
Cloudbric
Cloudbric
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
V
Vulnerabilities – Threatpost
C
Check Point Blog
Google DeepMind News
Google DeepMind News
Google Online Security Blog
Google Online Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cisco Blogs
Schneier on Security
Schneier on Security
O
OpenAI News
K
Kaspersky official blog

博客园 - 取经路上

IIS 下发布SignalR 访问接口进不去处理 Linux下部署.Net 应用程序和Web应用程序 CentOS 7 nginx 安装 sticky模块 关于SignalR并发量测试 C# 调用迅雷aplayer播放器的遇到的问题总结 C# 采用HttpWebRequest 、WebClient和HttpClient下载https的文件异常问题 C# 判别系统版本以及Win10的识别办法 MVC ActionResult 视图模型 MVC 前后台传值 MVC基础关键点 sqlserver 数据库、日志文件收缩 笔记 vue-cli启动报错问题: IE6无法获取class属性 windows server 2008 r2 datacenter 共享服务找不到网络路径解决办法 在Visual Studio 中的监视窗口中监视Com对象变量 删除GitHub上项目中的某个文件 转 WPF MVVM 循序渐进 (从基础到高级) 服务器未能识别 HTTP 头 SOAPAction 的值: http://tempuri.org/QueryUserName。
CentOS 7 配置启动 手动编译的 nginx
取经路上 · 2024-12-04 · via 博客园 - 取经路上

1.如何安装请参考之前的编译安装文章

手动编一个的nginx 一般在这个目录下:/usr/local/nginx

2.配置 Nginx 服务

2.1 创建 Systemd 服务文件

  1. 路径:/etc/systemd/system/nginx.service
    sudo vim /etc/systemd/system/nginx.service
  2. 内容:这里是推荐的配置文件:
[Unit]
Description=The Nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

2.2 配置文件分析

  • [Unit] 部分:
    • After=syslog.target network.target remote-fs.target nss-lookup.target:确保在其他服务启动后再启动 Nginx。
  • [Service] 部分:
    • Type=forking:使用 forking 类型,Nginx 启动后会生成子进程。
    • PIDFile:Nginx 主进程的 PID 文件路径。
    • ExecStartPre:在启动前执行 nginx -t 命令,检查配置文件是否正确。
    • ExecStart:启动 Nginx,指定配置文件路径。
    • ExecReload:重新加载 Nginx 配置。
    • ExecStop:优雅地停止 Nginx。
    • PrivateTmp=true:为 Nginx 提供独立的临时文件夹,提升安全性。

2.3 重新加载 Systemd 服务文件

sudo systemctl daemon-reload

3. 配置 Nginx 日志文件

确保你在 Nginx 配置文件 /usr/local/nginx/conf/nginx.conf 中正确设置了日志路径。例如:

error_log /usr/local/nginx/logs/error.log;
access_log /usr/local/nginx/logs/access.log;

4. 启动 Nginx 服务

4.1 启动 Nginx

sudo systemctl start nginx

4.2 检查 Nginx 服务状态

sudo systemctl status nginx

确认 Nginx 是否启动成功。如果出现错误,可以通过查看日志来诊断:

sudo journalctl -u nginx.service

5. 设置 Nginx 开机自启

sudo systemctl enable nginx

这会将 Nginx 添加到系统启动项中,使其在系统重启时自动启动。

6. 调试与常见问题解决

6.1 检查配置文件语法

在启动 Nginx 之前,确保 Nginx 配置文件没有语法错误: