1.安装工具和库
# pcre是一个perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式
# zlib库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.目录结构
源码目录:/home/werben/pkgsrc/nginx
安装目录:/home/werben/application/nginx
3.下载解压源码
wget -c
4.创建用户组和用户
groupadd www useradd -g www www
5.编译源码
./configure --user=www --group=www --prefix=/home/werben/application/nginx --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre make && make install
6.映射全局命令
ln -s /home/werben/application/nginx/sbin/nginx /usr/local/bin/nginx
7.启动,停止,重启
nginx -s stop nginx -s quit ngins -s reload
8.检测配置文件nginx.conf正确性
nginx -t
9.开机自启动
vim /lib/systemd/system/nginx.service [unit] description=nginx after=network.target [service] type=forking execstart=nginx execreload=nginx reload execstop=nginx quit privatetmp=true [install] wantedby=multi-user.target #重新加载守护进程 systemctl daemon-reload #启动nginx服务 systemctl start nginx.service #停止nginx服务 systemctl stop nginx.service #设置开机自启动 systemctl enable nginx.service #停止开机自启动 systemctl disable nginx.service #查看服务当前状态 systemctl status nginx.service #重新启动服务 systemctl restart nginx.service #查看所有已启动的服务 systemctl list-units --type=service
10.出现问题和解决方法
#如果`systemctl start nginx.service`提示如下报错 job for nginx.service failed because the control process exited with error code. see "systemctl status nginx.service" and "journalctl -xe" for details. #执行 systemctl status nginx.service #如果出现如下错误 process: 35783 execstart=...nginx/sbin/nginx(code=exitedstatus=203/exec) nginx.service: control process exited, code=exited status=203 systemd[1]: nginx.service: failed with result 'exit-code'. localhost.localdomain systemd[1]: failed to start nginx. journalctl -xe #如果看到如下信息 if you believe that systemd should be allowed execute access on the> then you should report this as a bug. you can generate a local policy module to allow this access. do allow this access for now by executing: # ausearch -c '(nginx)' --raw | audit2allow -m my-nginx # semodule -x 300 -i my-nginx.pp #解决方法 setenforce 0 vim /etc/selinux/config selinux=disabled
ps:nginx配置文件的结构说明
所有nginx配置文件都位于/etc/nginx/目录中。
nginx的主要配置文件是/etc/nginx/nginx.conf。
为每个域创建一个单独的配置文件使服务器易于维护。
nginx服务器阻止文件必须以结尾.conf并存储在/etc/nginx/conf.d目录中。您可以根据需要拥有任意数量的服务器块。
遵循标准命名约定是一个好习惯。例如,如果域名是,mydomain.com则配置文件应命名为mydomain.com.conf
如果在域服务器块中使用可重复的配置段,则最好将这些段重构为片段。
nginx日志文件(access.log和error.log)位于/var/log/nginx/目录中。建议有不同access和error日志文件每个服务器模块。
您可以将域文档的根目录设置为所需的任何位置。webroot的最常见位置包括:
/home/<user_name>/<site_name> /var/www/<site_name> /var/www/html/<site_name> /opt/<site_name> /usr/share/nginx/html
以上是centos8自定义目录安装nginx的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

NGINX可用于提升网站性能、安全性和可扩展性。1)作为反向代理和负载均衡器,NGINX可优化后端服务和分担流量。2)通过事件驱动和异步架构,NGINX高效处理高并发连接。3)配置文件允许灵活定义规则,如静态文件服务和负载均衡。4)优化建议包括启用Gzip压缩、使用缓存和调整worker进程。

NGINXUnit支持多种编程语言,通过模块化设计实现。1.加载语言模块:根据配置文件加载相应模块。2.应用启动:调用语言运行时执行应用代码。3.请求处理:将请求转发给应用实例。4.响应返回:将处理后的响应返回给客户端。

NGINX和Apache各有优劣,适合不同场景。1.NGINX适合高并发和低资源消耗场景。2.Apache适合需要复杂配置和丰富模块的场景。通过比较它们的核心特性、性能差异和最佳实践,可以帮助你选择最适合需求的服务器软件。

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

要关闭 Nginx 服务,请按以下步骤操作:确定安装类型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服务:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自动启动(可选):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

如何在 Windows 中配置 Nginx?安装 Nginx 并创建虚拟主机配置。修改主配置文件并包含虚拟主机配置。启动或重新加载 Nginx。测试配置并查看网站。选择性启用 SSL 并配置 SSL 证书。选择性设置防火墙允许 80 和 443 端口流量。

服务器无权访问所请求的资源,导致 nginx 403 错误。解决方法包括:检查文件权限。检查 .htaccess 配置。检查 nginx 配置。配置 SELinux 权限。检查防火墙规则。排除其他原因,如浏览器问题、服务器故障或其他可能的错误。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

禅工作室 13.0.1
功能强大的PHP集成开发环境

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境