nginx源码安装

目录

一、下载网络下载压缩包

二、创建用户 

三、安装一些依赖包 

四、编写脚本


一、下载网络下载压缩包

华为开源镜像站_软件开发服务_华为云

[root@localhost ~]# wget -c https://repo.huaweicloud.com/nginx/nginx-1.20.0.tar.gz

解压到指定位置

[root@localhost ~]# tar xf nginx-1.20.0.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/nginx-1.20.0/

二、创建用户 

创建用户
useradd -r -s /sbin/nologin -M nginx

三、安装一些依赖包 

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-threads --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_stub_status_module --with-stream --with-pcre
 
安装gcc gcc-c++ make
yum install gcc gcc-c++ make -y
安装pcre-devel
yum install pcre-devel -y
安装openssl
yum install openssl-devel -y
yum install perl-devel -y
yum install perl-ExtUtils-Embed -y

 如下就是该有的包都有了


[root@localhost nginx-1.20.0]# ./configure 

下一步 
make 

make install

tree /usr/local/nginx/

切换到此位置  cd /usr/local/nginx/sbin  

创建如下软连接

[root@localhost sbin]# ln -sv /usr/local/nginx/sbin/nginx /usr/sbin/nginx

#查看nginx版本 nginx -v

四、编写脚本

一定要写对路径不然可能启不起来

[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
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=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true


[Install]
WantedBy=multi-user.target
systemctl daemon-reload

此时就可以启动nginx了

systemctl start nginx

安装nginx源码,您可以按照以下步骤进行操作: 1. 首先,您需要下载nginx源码。您可以从官方网站上下载最新版本的源码。您可以在http://nginx.org/download/找到最新的源码下载链接。 2. 下载完成后,解压源码。您可以使用tar命令来解压文件。例如,如果您的源码nginx-1.20.1.tar.gz,您可以使用以下命令进行解压: ``` tar -zxvf nginx-1.20.1.tar.gz ``` 3. 进入解压后的目录: ``` cd nginx-1.20.1 ``` 4. 在源码目录中,执行configure命令进行配置。该命令将根据您的系统环境进行一些必要的配置: ``` ./configure ``` 5. 配置完成后,运行make命令编译源码: ``` make ``` 6. 编译完成后,运行make install命令将nginx安装到系统中: ``` make install ``` 7. 安装完成后,您可以检查是否成功安装nginx。您可以使用id命令来检查是否存在nginx用户: ``` id nginx ``` 以上就是nginx源码安装的一般步骤。请注意,这里只提供了基本的安装步骤,具体的安装过程可能会因系统环境和配置需求而有所不同。建议您在安装前阅读官方文档或参考更详细的安装指南以确保正确安装nginx。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [nginx源码安装](https://blog.csdn.net/weixin_49185464/article/details/127326489)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值