Linux 安装nginx1.24.0(亲测有效)

一、安装

1.创建nginx文件夹

mkdir /usr/local/

2.进入文件夹

 cd /usr/local/

3.下载安装包链接( 提取码:s8k6) 

https://pan.baidu.com/s/1iOdCOKnSQi-bmxTVD7Y_Rw?pwd=s8k6 
 

4.上传文件 

rz

5.云安装依赖

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 

6. 解析文件

tar -zxvf nginx-1.24.0.tar.gz

7.进入当前目录

cd nginx-1.24.0

 8.执行文件

./configure --prefix=/usr/local/nginx

9.编译命令

make 

10.安装命令

 make install

11.进入目录

cd /usr/local/nginx/sbin 

12.启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 二、防火墙设置

1.开放端口

firewall-cmd --add-port=80/tcp --permanent

2.重启防火墙

firewall-cmd --reload

3.从新加载配置

.nginx -s reload

4.重启

./nginx -t 

 三、开机自启

1.在/etc/systemd/system目录下创建一个名为nginx.service的文件:

sudo vim /etc/systemd/system/nginx.service

2.然后添加以下内容

[Unit]
Description=The NGINX HTTP and reverse proxy 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
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
 

3.重新加载systemd 

sudo systemctl daemon-reload

4.设置开机自启

sudo systemctl enable nginx.service 

5.启动Nginx服务

sudo systemctl start nginx.service 

6.检查服务状态

sudo systemctl status nginx.service 

7.重启系统测试

sudo reboot 

  • 11
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以按照以下步骤编译安装nginx 1.24.0: 1. 首先,下载nginx的源码包。您可以访问官方网站的下载页面,找到对应版本的源码包,并将其下载到您的CentOS服务器上。 2. 安装编译nginx所需的依赖项。 3. 解压源码包,并进入解压后的目录。 4. 运行配置命令,指定安装路径、用户和组,并选择需要的模块。例如: ``` ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module ``` 这个命令将设置nginx安装路径为`/usr/local/nginx`,将使用`nginx`用户和组运行nginx,并启用`stub_status`模块。 5. 运行`make`命令编译nginx,并使用`make install`命令安装nginx。 6. 创建nginx用户组,以及nginx用户,并指定其使用`/sbin/nologin`作为shell。 7. 解压下载的源码包,并进入解压后的目录。 8. 运行配置命令,指定用户和组,以及其他需要的模块。例如: ``` ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-openssl=/usr/local/openssl ``` 这个命令将设置nginx的用户和组为`nginx`,安装路径为`/usr/local/nginx`,并启用一些常用的模块,如`stream`模块、`http_ssl`模块和`http_gzip_static`模块等。 9. 运行`make`命令编译nginx,并使用`make install`命令安装nginx。 10. 配置启动脚本。将nginx可执行文件拷贝到`/etc/rc.d/init.d/`目录,并设置正确的权限。然后,使用`chkconfig`命令将nginx添加到系统服务,并使用`service`命令启动nginx。 ``` cp /opt/nginx-1.24.0/nginx /etc/rc.d/init.d/ chmod 744 /etc/rc.d/init.d/nginx chkconfig nginx on service nginx start ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值