JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Nginx 最全操作——nginx安装(1)

wys521 2024-09-04 15:36:29 精选教程 39 ℃ 0 评论

安装 nginx

下载 nginx 压缩包文件到自定义目录/opt,官网下载地址:http://nginx.org/download/nginx-1.21.5.tar.gz

笔者现在看是使用的主线版本:nginx-1.21.5

注意:如果是生产环境的话,建议使用稳定版本,截至笔者发文时,

稳定版本为nginx-1.20.2

yum update #更新所有系统软件包
cd /opt
wget http://nginx.org/download/nginx-1.21.5.tar.gz

解压 tar.gz 压缩包文件,进去 nginx-1.21.5

tar -xzvf nginx-1.21.5.tar.gz
cd nginx-1.21.5

进入文件夹后进行配置检查

./configure

通过安装前的配置检查,这里发现有报错。其中是因为在检查中发现一些依赖库没有找到,这时候需要先安装 nginx 的一些依赖库

yum -y install pcre* #安装使nginx支持rewrite
yum -y install gcc-c++
yum -y install zlib*
yum -y install openssl openssl-devel

再次进行检查操作 ./configure 没发现报错显示,然后进行编译并安装

 // 检查nginx模块支持
./configure  --prefix=/usr/local/nginx  --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-threads --user=www --group=www

这里需要特别注意,以后需要用到的功能模块是否存在,否则以后添加新功能会比较麻烦。

查看默认安装的模块支持

我们可以使用命令 ls nginx-1.21.5 查看 nginx 打开文件列表,可以发现里面有一个 auto 的目录。

在这个 auto 目录中有一个 options 文件,这个文件里面保存的就是 nginx 编译过程中的所有选项配置。

通过命令:cat nginx-1.21.5/auto/options | grep YES就可以查看

nginx 编译安装时,怎么查看安装模块

编译并安装

make && make install

这里需要注意,模块的支持跟后续的 nginx 配置有关,比如 SSL,gzip 压缩等等,编译安装前最好检查需要配置的模块存不存在。

通过whereis查看 nginx 安装后台的目录,可以看到已经默认安装到 /usr/local/nginx 目录了

whereis nginx
nginx: /usr/local/nginx

启动 nginx 服务

cd /usr/local/nginx/sbin/
./nginx

错误展示:

服务启动的时候报错了:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) ,可以通过命令查看本机网络地址和端口等,找到被占用的位置 80 端口

netstat -ntlp 的 tcp 连接,并杀死进程(kill 进程 pid)

netstat -ntlp l kill 进程PID

继续启动 nginx 服务,启动成功

./nginx

在浏览器直接访问安装服务器的ip 地址,页面出现 Welcome to Nginx! 则安装成功。至此nginx安装部分就大功告成了。


欢迎大家提出不一样的观点,我们一起讨论,

我是辣个男人,一个运维人。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表