×

QQ登录

只需一步,快速开始

【编译安装】Nginx linux编译安装

标签: 暂无标签
1.首先进入官网下载最新的稳定分支。
EMA0G)4E74_RLK()[@(P3CE.png

2.下载后上传到服务器并解压,进入解压的文件夹。

这里对解压完成后的部分目录和文件做个简单的介绍:
  • src 该目录存放了Nginx的所有源码;
  • man 该目录存放了Nginx的帮助文档;
  • html 该目录存放了两个html文件。这两个文件与Nginx服务器的运行相关,这两个文件的作用会在下文给出,这里不做赘述;
  • conf 该目录存放的是Nginx服务器的配置文件,包含Nginx服务器的基本配置文件;
  • auto 该目录存放了大量脚本文件,和configure脚本程序有关;
  • configure 该文件是Nginx软件的自动脚本程序。运行configure脚本一般会完成两项工作:一是检查环境,根据环境检查结果生成C代码;二是生成编译代码需要的Makefile文件。


[Bash shell] 纯文本查看 复制代码
tar -xzvf nginx-1.22.0.tar.gz
cd nginx-1.22.0


QQ截图20220810163216.png


3.配置编译环境
[Bash shell] 纯文本查看 复制代码
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel


[Bash shell] 纯文本查看 复制代码
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --with-pcre-jit --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-stream --with-stream_ssl_module


如果出现这种报错,源码编译安装最新的openssl, 然后重新在上面的命令后面加上一条--with-openssl=你openssl的源码路径
1660122488744.jpg
[Bash shell] 纯文本查看 复制代码
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --with-pcre-jit --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/opt/openssl-1.1.1q


4.编译安装


[Bash shell] 纯文本查看 复制代码
make && make install

QQ截图20220810171403.png

5.配置nginx服务启动。
去到/usr/lib/systemd/system/目录新建一个nginx服务,给予执行权限:
[Bash shell] 纯文本查看 复制代码
vim /usr/lib/systemd/system/nginx.service
chmod +x /usr/lib/systemd/system/nginx.service

打开文件nginx.service新建内容:
[Bash shell] 纯文本查看 复制代码
[Unit]                                                                                      
Description=nginx - high performance web server              
After=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=/usr/local/nginx/sbin/nginx -s reload                                                 
ExecStop=/usr/local/nginx/sbin/nginx -s stop                                                       
ExecQuit=/usr/local/nginx/sbin/nginx -s quit                                                        
PrivateTmp=true                                                                  

[Install]
WantedBy=multi-user.target 

保存之后重载Ststemctl命令:
[Bash shell] 纯文本查看 复制代码
systemctl daemon-reload


6.设置自启动
[Bash shell] 纯文本查看 复制代码
systemctl enable nginx


7.命令
[Bash shell] 纯文本查看 复制代码
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx


Felix

2022年8月10日 17:15

落叶

写了 57 篇文章,拥有财富 3674,被 1 人关注

卧槽
转播转播 分享分享 分享淘帖 踩
回复

使用道具

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

Archiver|手机版|小黑屋|华盟游戏社区
Powered by Hommon Tech. © 2019
返回顶部