centos7制作免安装nginx

一、准备环境

1、安装依赖

在可以联网的服务器上执行以下命令

yum -y install gcc gcc-c++ make automake autoconf libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

2、下载想要版本的nginx

wget https://nginx.org/download/nginx-1.24.0.tar.gz

二、编译配置

tar -zxvf nginx-1.24.0.tar.gz
cd nginx-1.24.0

修改编译参数

./configure --prefix=/opt/project/public/nginx-portable \
    --with-http_ssl_module \
    --with-http_gzip_static_module \
    --without-http_autoindex_module \
    --without-http_userid_module \
    --with-http_realip_module

--prefix:安装路径,之后在需要免安装的服务器上也要放到这个路径。

三、编译并安装

make && make install

编译完成会在prefix目录生成这四个目录:conf、html、logs、sbin。

四、打包免安装包

cd /opt/project/public
tar -zcvf nginx-portable.tar.gz ./nginx-portable

四、在目标服务器使用免安装包部署

cd /opt/project/public
tar -zxvf nginx-portable.tar.gz

启动(如果用非root用户启动,需要修改nginx.conf的80端口为1024以上)
/opt/project/public/nginx-portable/sbin/nginx

五、验证

访问http://目标服务器ip:nginx端口,看到Welcome to nginx!就是部署成功。


image.png

六、注册为系统服务(可选)

vim /etc/systemd/system/nginx.service

[Unit]
Description=Nginx Portable Server
After=network.target

[Service]
Type=forking
PIDFile=/opt/project/public/nginx-portable/logs/nginx.pid
ExecStart=/opt/project/public/nginx-portable/sbin/nginx
ExecReload=/opt/project/public/nginx-portable/sbin/nginx -s reload
ExecStop=/opt/project/public/nginx-portable/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动服务

systemctl daemon-reload
systemctl enable --now nginx
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容