wlnmp一键安装包Nginx使用指南

引言

本文档旨在提供关于在wlnmp一键安装包所支持的系统中安装、配置和启动Nginx的详细指南。Nginx作为一款高性能的Web服务器和反向代理服务器,广泛应用于互联网领域。通过本文档,你将了解到如何在你的系统上轻松安装、配置和管理Nginx,从而为你的网站或应用程序提供稳定可靠的服务。

1. nginx的安装与卸载

遵循wlnmp一键安装包官网“安装使用”教程。

1.1 添加epel源

请注意,如果不添加epel源,在安装nginx时可能会提示nothing provides libprofiler.so.0()(64bit)错误,这是因为有些依赖包组在epel源中。

1.2 添加wlnmp源

1.3 安装nginx

请注意,同类型的web服务器软件在系统中同时仅可以存在一个,比如装了nginx就不能装Apache httpd,默认nginx中已集成lua模块,在安装nginx时会同时安装wluaJIT2包。

1.4 卸载nginx

请注意,卸载后在/usr/local/nginx/和/data/logs/nginx/目录下,还会保留部分配置、日志文件,如确定不再需要,可以对这两个目录进行删除操作,即rm -rf /usr/local/nginx/ /data/logs/nginx/,此时完美卸载完成,没有其它残留文件。

1.5 升级nginx

请注意,当wlnmp一键安装包有更新时,可直接通过yum update wnginx方式直接升级,升级前请做好重要数据备份,避免由于某些原因导致升级失败,升级时不会覆盖原有正在使用的配置文件,但会导致nginx服务重启。

1.6 查询nginx所包含的文件

我们可以通过rpm -ql wnginx来查看,wnginx包产生了哪些文件。

2. nginx的配置

2.1 配置文件目录

遵循标准编译路径配置,默认nginx配置目录在/usr/local/nginx/下。

2.2 配置php支持

在/usr/local/nginx/conf/vhost/demo.conf中启用include enable-phpXX.conf;字段即可,需要哪个版本的php就启用哪个,如果已删除了demo.conf文件,可在需要的server字段中增加。

include enable-php56.conf;
include enable-php70.conf;
include enable-php71.conf;
include enable-php72.conf;
include enable-php73.conf;
include enable-php74.conf;
include enable-php8.conf;
include enable-php81.conf;
include enable-php82.conf;
include enable-php83.conf;

2.3 默认包含的模块

可通过nginx -V进行查看,截至本文档发文,目前nginx所支持的模块如下

nginx version: nginx/1.24.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-20) (GCC)
built with OpenSSL 3.0.13 30 Jan 2024
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --add-module=ngx_devel_kit-0.3.2 --add-module=lua-nginx-module-0.10.24 --with-cc-opt='-O2 -fstack-protector-strong -mtune=generic -fstack-clash-protection' --with-ld-opt='-Wl,-rpath,$LUAJIT_LIB -Wl,-z,relro -Wl,-z,now' --add-module=ngx_cache_purge-2.3 --with-http_realip_module --with-google_perftools_module --with-stream --with-openssl=openssl-3.0.13 --without-pcre2 --with-http_mp4_module --with-http_flv_module --with-http_gunzip_module --with-http_image_filter_module --with-http_random_index_module --with-http_realip_module --with-http_slice_module --with-http_stub_status_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_secure_link_module --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=njs-0.8.3/nginx --with-select_module

2.4 日志转储

已集成logrotate日志转储,默认log日志请指向/data/logs/nginx/目录下,并以.log结尾,通过/etc/logrotate.d/nginx预设的规则,所有以.log结尾的日志文件将在每天执行一次(通常在凌晨,没有固定的时间),保留最新的10个日志文件,旧的日志文件将被压缩并追加日期,同时发送信号给Nginx进程以切换到新的日志文件。

3. 启动和管理nginx

wlnmp一键安装包所安装的nginx,支持传统的SysV和现代的systemd两种管理方式,并且可以通用。

3.1 查询nginx状态

查询nginx启动状态可以使用以下两种命令(任选其一)

3.2 停止nginx

停止nginx可以使用以下两种命令(任选其一)

3.3 启动nginx

启动nginx可以使用以下两种命令(任选其一)

请注意,并没有明确要求用哪种方式启动管理nginx,你可以通过/etc/init.d/nginx start,然后systemctl stop nginx停止,请结合个人喜好进行选择,推荐使用/etc/init.d/nginx方式,因为可以通过TAB命令补全。

4. 结论

通过本文档,可以详细的了解到nginx的包安装、配置和管理等,请根据你的实际需求进行配置和调整,了解nginx软件更多信息,请参阅nginx官方文档或其它相关资源。

本文档结合实际情况及使用需求不定期进行更新,对于有一定Linux运维经验的用户来说,非常容易上手。