Linux nginx1.22.0安装及注册服务

官网 https://nginx.org/下载对应的nginx包,推荐使用稳定版本

在这里插入图片描述
1.下载安装文件

# 下载安装文件
wget http://nginx.org/download/nginx-1.22.0.tar.gz

2.安装依赖环境

# 安装gcc环境
yum install gcc-c++
# 安装PCRE库,用于解析正则表达式
yum install -y pcre pcre-devel
# zlib压缩和解压缩依赖
yum install -y zlib zlib-devel
# SSL安全的加密的套接字协议层,用于HTTP安全传输,也就是https
yum install -y openssl openssl-devel
# 解压,需要注意,解压后得到的是源码,源码需要编译后才能安装
tar -zxvf nginx-1.22.0.tar.gz
# 编译之前,先创建nginx临时目录,如果不创建,在启动nginx过程中会报错
mkdir /var/temp/nginx -p

# 进入解压后的nginx目录 cd nginx-1.22.0/ ,输入如下命令进行配置,目的是为了创建makefile文件
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

在这里插入图片描述

3.make编译安装

# make编译
make
# 安装
make install

4.启动

# 进入sbin目录 cd /usr/local/nginx/sbin/ 下,
# 启动
./nginx 
# 停止: 
./nginx -s stop
# 重新加载: 
./nginx -s reload

5.测试
打开windows浏览器,访问虚拟机所处内网ip地址即可打开nginx的默认页面,即成功
在这里插入图片描述
6.把 nginx 配置成一个服务

vi /etc/init.d/nginx

服务脚本:

#!/bin/sh
#chkconfig: - 85 15
 
PATH=/usr/local/nginx/sbin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
 
set -e
[ -x "$DAEMON" ] || exit 0
 
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
 
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
 
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
 
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0

保存后赋予权限:

chmod 777 nginx

添加服务:

chkconfig --add nginx

测试命令

# 启动:
systemctl start nginx.service
# 停止:
systemctl stop nginx.service
# 重启:
systemctl restart nginx.service
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 1. 下载nginx1.22.0源码包 2. 解压源码包:tar -zxvf nginx-1.22.0.tar.gz 3. 安装依赖库:yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 4. 进入nginx源码目录:cd nginx-1.22.0 5. 配置编译选项:./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module 6. 编译安装:make && make install 7. 启动nginx:/usr/local/nginx/sbin/nginx 8. 验证nginx是否启动成功:访问http://localhost,如果出现“Welcome to nginx!”则表示安装成功。 ### 回答2: 安装编译前的准备 在开始安装编译Linux Nginx之前,您需要在服务器上安装一些准备工作。下面是一些必要的准备工作。 1. 确保服务器上已经安装了GCC(GNU Compiler Collection)。 2. 确保服务器上已经安装了Make工具。 3. 在安装Linux Nginx之前,必须安装PCRE(Perl Compatible Regular Expressions)和zlib库。这些库用于提供正则表达式的支持和压缩算法。 4. 确保已经安装了OpenSSL(Secure Sockets Layer)库。这些库用于提供安全的HTTP传输协议。 步骤1:下载Linux Nginx 首先,您需要下载Linux Nginx。请选择可靠的站点或官方网站以确保文件是安全的。 此外,您也可以使用wget命令从服务器上下载Linux Nginx。例如: $ wget http://nginx.org/download/nginx-1.22.0.tar.gz 步骤2:解压缩Linux Nginx 下载完成后,您需要使用以下命令来将Linux Nginx解压缩。 $ tar -zxvf nginx-1.22.0.tar.gz 步骤3:编译并安装 在解压缩完成后,您需要切换到存储目录并开始编译安装。 $ cd nginx-1.22.0 $ ./configure --with-http_ssl_module $ make $ make install 请注意,上面的编译选项“--with-http_ssl_module”用于启用SSL模块。 步骤4:运行Linux Nginx 在编译安装完成后,您需要启动Linux Nginx。使用以下命令来启动。 $ nginx 此外,您还可以使用以下一些操作来控制Linux Nginx的行为。 $ nginx -s stop // 停止Nginx。 $ nginx -s quit // 优雅地停止Nginx。 $ nginx -s reload // 重新加载配置文件。 总结 编译安装Linux Nginx的过程相对简单,但需要一些准备工作和基本的Linux知识。在安装之前,请确保具备所需的先决条件,并根据需要进行设置和配置。使用上述步骤,您可以轻松编译和安装Linux Nginx,并使用其提供的高性能的HTTP和Web服务器功能。 ### 回答3: linux系统是一种基于UNIX操作系统的自由软件和开源软件,被广泛应用于各种领域。NGINX是一种高性能、高可靠性的Web服务器和反向代理服务器,被广泛应用于负载均衡、缓存、HTTP代理等方面。本文将详细介绍在linux系统下编译安装NGINX1.22.0的步骤及注意事项。 一、环境准备 首先需要确保linux系统中已经安装了必要的依赖库,例如gcc、pcre、openssl、zlib等。可以通过以下命令进行检查和安装: ``` $ sudo apt-get update $ sudo apt-get install gcc $ sudo apt-get install libpcre3 libpcre3-dev $ sudo apt-get install openssl libssl-dev $ sudo apt-get install zlib1g-dev ``` 二、下载NGINX源码 在编译安装NGINX之前,需要先从官方网站(https://nginx.org/en/download.html)下载最新版的源码包。下载完成后,将源码包解压到指定目录中,例如: ``` $ tar -zxvf nginx-1.22.0.tar.gz $ cd nginx-1.22.0 ``` 三、配置编译参数 在编译安装NGINX之前,需要为NGINX配置编译参数,例如安装目录、模块、日志等。可以通过以下命令进行配置: ``` $ sudo ./configure \ --prefix=/usr/share/nginx \ --sbin-path=/usr/sbin/nginx \ --modules-path=/usr/lib/nginx/modules \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --with-threads \ --with-http_addition_module \ --with-http_auth_request_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_mp4_module \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_v2_module \ --with-mail \ --with-mail_ssl_module \ --with-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-compat \ --with-pcre \ --with-pcre-jit \ --with-openssl \ --with-zlib ``` 其中常用的参数解释如下: prefix:指定安装的目录; sbin-path:指定NGINX的可执行文件路径; modules-path:指定NGINX模块的安装路径; conf-path:指定NGINX的配置文件路径; error-log-path:指定NGINX的错误日志路径; http-log-path:指定NGINX的访问日志路径; pid-path:指定NGINX的进程ID文件路径; user/group:指定运行NGINX的用户和组; with-xxx:指定要编译的模块; with-compat:是为了保持NGINX现有配置和第三方模块的兼容性。 四、编译安装 在完成了配置编译参数后,可以通过以下命令进行编译和安装: ``` $ sudo make $ sudo make install ``` 如果编译和安装过程没有出现错误提示,则说明NGINX已经成功安装到了指定目录中。 五、启动NGINX 完成了NGINX的编译安装后,需要通过以下命令启动NGINX: ``` $ sudo /usr/sbin/nginx ``` 如果没有出现错误提示,则说明NGINX已经启动成功。可以通过访问http://localhost:80测试NGINX是否能正常响应。 六、总结 在linux系统下编译安装NGINX1.22.0并不困难,需要先准备好必要的依赖库,下载源码并配置编译参数,最后进行编译和安装。同时,可以根据自己的需要进行相应的参数配置,例如安装目录、模块等。在NGINX启动后,可以通过http://localhost:80进行访问,测试是否能正常响应。使用NGINX可以大大提高Web服务器的性能和可靠性,对于高并发和大流量的场景更是有很好的应用效果。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值