nginx免安装二进制包制作(安装推荐)

nginx官网

nginx官方网站 https://nginx.org/download/

安装包下载

zip和tar.gz

https://nginx.org/download/

rpm包下载(官方rpm包下载地址)

http://nginx.org/packages/rhel/7/x86_64/RPMS/

安装

使用二进制包安装
建议在网络隔离环境并且无root用户下安装(rpm包 和 源码包及yum安装依赖时需要使用root用户安装,如果没有root用户就无法安装了)。

1.16.1免安装包下载

下载后在服务器上解压即可
1.16.1的免安装包 https://cikeblog.com/s/nginx-1.16.1.tar.gz

制作免安装包

如果github打开慢,可以通过阿里云或者其他环境下载对应的包Nginx-portable

参考 https://my.oschina.net/u/4354892/blog/4080875

1.下载nginx-portable-master

# 下载 & 解压 & 进入解压目录
wget https://github.com/nuccch/nginx-portable/archive/master.zip && unzip master && cd nginx-portable-master

2. 编译指定版本

打nginx编译准备

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

然后执行:

bash compile <nginx-version>

举个例子,我们要编译1.18.1版本:

bash compile 1.18.1

其他版本以此类推,编译完成后,会在当前目录的build目录下生成一个已经编译好的nginx文件:

nginx-<version>.tar.gz

在这里插入图片描述

部署

将做到的二进制包放到需要部署的服务器,这里使用1.18.0部署

上传并解压
$ tar -zxf nginx-1.18.0.tar.gz
启动

进入目录

#启动nginx
$ cd nginx-.1.18.0 && ./sbin/nginx

可以看到nginx已经启动
在这里插入图片描述
如有防火墙需关闭防火墙或开放端口之后可以访问部署页面

  • 开放端口
# centos7
# 开放端口 firewall-cmd --zone=public --add-port=80-90/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
#sudo systemctl reload firewalld
firewall-cmd --reload

# 一行
firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload

输出结果

[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload
success
success
  • 关闭防火墙
# 关闭防火墙
systemctl stop firewalld
查看信息

查看版本和模块信息 ./sbin/nginx -V,看情况创建目录
–http-client-body-temp-path=tmp/client_body_temp/ --http-proxy-temp-path=tmp/proxy_temp/ --http-fastcgi-temp-path=tmp/fastcgi_temp/ --http-uwsgi-temp-path=tmp/uwsgi_temp/ --http-scgi-temp-path=tmp/scgi_temp/
创建目录语句

$ cd $nginx_home/tmp && mkdir -p client_body_temp proxy_temp fastcgi_temp uwsgi_temp scgi_temp
[root@localhost nginx-1.18.0]# ./sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=. --sbin-path=sbin/ --conf-path=conf/nginx.conf --error-log-path=logs/error.log --http-client-body-temp-path=tmp/client_body_temp/ --http-proxy-temp-path=tmp/proxy_temp/ --http-fastcgi-temp-path=tmp/fastcgi_temp/ --http-uwsgi-temp-path=tmp/uwsgi_temp/ --http-scgi-temp-path=tmp/scgi_temp/ --with-ipv6 --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_fastcgi_module

yum 安装

有网络的环境会自动下载依赖,如果无网络的环境需要安装依赖包
默认1.12.2版本的nginx
在这里插入图片描述
安装,这里使用root安装

# 安装
$ yum install -y nginx

rpm包安装

rpm -ivh  nginx.xxx.rpm

nginx常用命令

启动:cd /nginx/sbin && ./nginx
停止:./nginx -s stop
重启:./nginx -s reload
检查配置正确性:./nginx -t
查看Nginx版本信息:./nginx -v
查看Nginx版本信息和配置:./nginx -V
Github项目地址:https://github.com/nuccch/nginx-portable

碰到的错误

启动nginx非root用户,不能使用80端口
在这里插入图片描述

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值