在 Debian 12.5 上编译安装 Nginx
<div class="cnblogs_code"><pre>root@debian:~# cat /etc/systemd/system/<span style="color: rgba(0, 0, 0, 1)">nginx.service
Description</span>=<span style="color: rgba(0, 0, 0, 1)">Nginx Service
Documentation</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http://nginx.org/en/docs/</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
After</span>=network.target remote-fs.target nss-<span style="color: rgba(0, 0, 0, 1)">lookup.target
Type</span>=<span style="color: rgba(0, 0, 0, 1)">forking
PIDFile</span>=/usr/local/nginx/logs/<span style="color: rgba(0, 0, 0, 1)">nginx.pid
ExecStartPre</span>=/usr/local/nginx/sbin/nginx -<span style="color: rgba(0, 0, 0, 1)">t
ExecStart</span>=/usr/local/nginx/sbin/<span style="color: rgba(0, 0, 0, 1)">nginx
ExecReload</span>=/usr/local/nginx/sbin/nginx -<span style="color: rgba(0, 0, 0, 1)">s reload
ExecStop</span>=/bin/kill -<span style="color: rgba(0, 0, 0, 1)">s QUIT $MAINPID
PrivateTmp</span>=<span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">
LimitNOFILE</span>=<span style="color: rgba(128, 0, 128, 1)">200000</span><span style="color: rgba(0, 0, 0, 1)">
WantedBy</span>=multi-user.target</pre>
</div>
<p> </p>
<p> </p>
<p>1. 更新系统软件包并安装必要的构建工具和依赖项:sudo apt update<br>sudo apt upgrade<br>sudo apt install build-essential zlib1g-dev libpcre3-dev libssl-dev<br>bash2. 下载 Nginx 源码包:wget http://nginx.org/download/nginx-x.y.z.tar.gz # 替换 x.y.z 为你要安装的 Nginx 版本号<br>tar zxf nginx-x.y.z.tar.gz<br>cd nginx-x.y.z<br>bash3. 配置 Nginx:./configure \<br> --prefix=/usr/local/nginx \<br> --user=www-data \<br> --group=www-data \<br> --with-http_ssl_module \<br> --with-http_v2_module \<br> --with-http_realip_module \<br> --with-http_gzip_static_module \<br> --with-http_stub_status_module \<br> --with-file-aio \<br> --with-threads \<br> --with-compat \<br> --add-module=path/to/optional/module # 如果你有额外模块需要编译进去<br><br># 注意替换 `path/to/optional/module` 为你实际的第三方模块路径<br>bash4. 编译和安装 Nginx:make<br>sudo make install<br>bash5. 创建系统启动所需的链接和服务文件(可选,根据你的启动方式):# 创建系统服务文件<br>sudo nano /etc/systemd/system/nginx.service<br><br># 在文件中填入类似以下内容:<br><br>Description=A high performance web server and a reverse proxy server<br>After=network.target<br><br><br>ExecStart=/usr/local/nginx/sbin/nginx<br>ExecReload=/usr/local/nginx/sbin/nginx -s reload<br>ExecStop=/usr/local/nginx/sbin/nginx -s quit<br>PrivateTmp=true<br><br><br>WantedBy=multi-user.target</p>
<p> </p>
<p>or</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">
Description</span>=<span style="color: rgba(0, 0, 0, 1)">Nginx Service
Documentation</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http://nginx.org/en/docs/</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
After</span>=network.target remote-fs.target nss-<span style="color: rgba(0, 0, 0, 1)">lookup.target
Type</span>=<span style="color: rgba(0, 0, 0, 1)">forking
PIDFile</span>=/usr/local/nginx/logs/<span style="color: rgba(0, 0, 0, 1)">nginx.pid
ExecStartPre</span>=/usr/local/nginx/sbin/nginx -<span style="color: rgba(0, 0, 0, 1)">t
ExecStart</span>=/usr/local/nginx/sbin/<span style="color: rgba(0, 0, 0, 1)">nginx
ExecReload</span>=/usr/local/nginx/sbin/nginx -<span style="color: rgba(0, 0, 0, 1)">s reload
ExecStop</span>=/bin/kill -<span style="color: rgba(0, 0, 0, 1)">s QUIT $MAINPID
PrivateTmp</span>=<span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">
LimitNOFILE</span>=<span style="color: rgba(128, 0, 128, 1)">200000</span><span style="color: rgba(0, 0, 0, 1)">
WantedBy</span>=multi-user.target</pre>
</div>
<p> </p>
<p><br><br># 保存退出,加载服务并启动 Nginx<br>sudo systemctl daemon-reload<br>sudo systemctl enable nginx<br>sudo systemctl start nginx<br><br># 检查服务状态<br>sudo systemctl status nginx<br>bash注意事项:•请确保你在配置 Nginx 时包含了所有你所需要的模块,比如 SSL、HTTP2、PHP-FPM 等。•/usr/local/nginx 是 Nginx 的安装路径,你可以根据需要更改。•用户名 www-data 在 Debian 上通常是 Web 服务使用的默认用户和组,可以根据实际情况更改。•最新版 Nginx 的配置选项可能有所不同,请查阅 Nginx 官方文档以获得最新配置指南。记得根据实际情况调整命令中的路径和模块选项。同时,请始终关注 Nginx 官方发布的安全更新,并适时更新你的 Nginx 服务器。</p><br><br>
来源:https://www.cnblogs.com/jason-zhao/p/18065903
頁:
[1]