千家信息网

centos8如何自定义目录安装nginx

发表于:2024-10-28 作者:千家信息网编辑
千家信息网最后更新 2024年10月28日,这篇文章给大家分享的是有关centos8如何自定义目录安装nginx的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1.安装工具和库# PCRE是一个Perl库,包括 per
千家信息网最后更新 2024年10月28日centos8如何自定义目录安装nginx

这篇文章给大家分享的是有关centos8如何自定义目录安装nginx的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

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.下载解压源码

# 官网地址: https://nginx.org/en/download.html
wget -c https://nginx.org/download/nginx-1.17.5.tar.gz

4.创建用户组和用户

groupadd wwwuseradd -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-pcremake && make install

6.映射全局命令

ln -s /home/werben/application/nginx/sbin/nginx /usr/local/bin/nginx

7.启动,停止,重启

nginx -s stopnginx -s quitngins -s reload

8.检测配置文件nginx.conf正确性

nginx -t

9.开机自启动

vim /lib/systemd/system/nginx.service[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=nginxExecReload=nginx reloadExecStop=nginx quitPrivateTmp=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 0vim /etc/selinux/configSELINUX=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///var/www//var/www/html//opt//usr/share/nginx/html

感谢各位的阅读!关于"centos8如何自定义目录安装nginx"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

服务 文件 目录 配置 服务器 内容 源码 位置 方法 日志 更多 模块 正则 用户 篇文章 结构 表达式 不同 不错 实用 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 电脑网络安全模式怎么打字 网吧服务器删除龙管家 gis空间数据库的连接 赣州星创网络技术有限公司 做c 软件开发的流程 网络技术考试题目讲解 游拍网络技术有限公司 数据库给别的用户赋权 开展网络安全培训报道 网络技术试验验证平台 棋牌游戏用国内服务器安全吗 有什么软件开发平台 数据库技术要编程吗 网络技术控制台怎么进出 网络安全科普教育手抄报的字 培训app软件开发中心 哪些医院有数据库管理员 成都软件开发公司如何收费 泰拉瑞亚手机联机服务器ip地址 社交网络技术研发 寻甸方便软件开发厂家价格 赣州星创网络技术有限公司 美屋互联网科技有限公司 方舟成为服务器管理员 聚聘互联网科技有限公司的架构 广东web应用软件开发技能大赛 韶华网络技术广州公司 计算机网络技术基础第二版盛立军 网络安全入门精通 服务器管理ip如何设置在哪
0