Centos离线安装Nginx
1. 下载nginx安装包
首先,我们需要下载nginx
的安装包。可以在官网上下载最新版本的nginx
安装包,也可以在其他网站上下载。
这里我们以nginx-1.25.2
版本为例,下载地址为:http://nginx.org/download/nginx-1.25.2.tar.gz
2. 安装依赖包
在安装nginx
之前,需要先安装一些依赖包。可以通过以下命令安装:
yum install -y gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
3. 解压安装包
将下载的nginx
安装包解压到指定目录,例如:
tar zxvf nginx-1.25.2.tar.gz -C /mnt/
4. 编译安装
进入解压后的nginx
目录,执行以下命令进行编译安装:
cd /mnt/nginx-1.25.2/
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
make && make install
其中,--prefix指定了nginx的安装目录,--with-http_ssl_module表示支持https协议,--with-http_stub_status_module表示支持查看nginx状态,--with-http_gzip_static_module表示支持gzip压缩。
5. 配置nginx
在安装目录下创建conf
目录,并在其中创建nginx.conf
文件,例如:
mkdir /usr/local/nginx/conf
vi /usr/local/nginx/conf/nginx.conf
在nginx.conf
文件中添加以下内容:
user nginx;
worker_processes 1;
error_log /usr/local/nginx/logs/error.log;
pid /usr/local/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
}
}
其中,user指定了nginx运行的用户,worker_processes指定了nginx启动的进程数,error_log指定了错误日志文件路径,pid指定了进程id文件路径,events指定了nginx的事件模型,http指定了http协议相关的配置,server指定了虚拟主机的配置,location指定了url的匹配规则和对应的处理方式。
6. 创建nginx用户
useradd nginx
7. 启动nginx
执行以下命令启动nginx
:
/usr/local/nginx/sbin/nginx
8. 验证nginx是否启动成功
在浏览器中输入服务器的ip地址或域名,如果能够正常访问nginx的欢迎页面,则说明nginx已经成功安装并启动。
至此,centos7离线安装nginx的过程就完成了。
©版权声明:
作者:xiaofu
文章标题:Centos离线安装Nginx
文章地址:https://blog.xf0.cc/193.html
作者地址:https://blog.xf0.cc/author/xiaofu
来源:Fu Zai's Notes
文章版权归作者所有,未经允许请勿转载。
作者:xiaofu
文章标题:Centos离线安装Nginx
文章地址:https://blog.xf0.cc/193.html
作者地址:https://blog.xf0.cc/author/xiaofu
来源:Fu Zai's Notes
文章版权归作者所有,未经允许请勿转载。
THE END
3
二维码
海报
Centos离线安装Nginx
1. 下载nginx安装包
首先,我们需要下载nginx 的安装包。可以在官网上下载最新版本的nginx 安装包,也可以在其他网站上下载。
这里我们以nginx-1.25.2 版本为……

文章目录
关闭
流量卡知识网