centos8自定义目录安装nginx(教程详解)
1.安装工具和库
#PCRE是一个Perl库,包括perl兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式
#zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip
yum-yinstallgcc-c++pcrepcre-develzlibzlib-developensslopenssl-devel
2.目录结构
源码目录:/home/werben/pkgsrc/nginx
安装目录:/home/werben/application/nginx
3.下载解压源码
#官网地址:https://nginx.org/en/download.html
wget-chttps://nginx.org/download/nginx-1.17.5.tar.gz
4.创建用户组和用户
groupaddwww useradd-gwwwwww
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&&makeinstall
6.映射全局命令
ln-s/home/werben/application/nginx/sbin/nginx/usr/local/bin/nginx
7.启动,停止,重启
nginx-sstop nginx-squit ngins-sreload
8.检测配置文件nginx.conf正确性
nginx -t
9.开机自启动
vim/lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=nginx ExecReload=nginxreload ExecStop=nginxquit PrivateTmp=true [Install] WantedBy=multi-user.target #重新加载守护进程 systemctldaemon-reload #启动nginx服务 systemctlstartnginx.service #停止nginx服务 systemctlstopnginx.service #设置开机自启动 systemctlenablenginx.service #停止开机自启动 systemctldisablenginx.service #查看服务当前状态 systemctlstatusnginx.service #重新启动服务 systemctlrestartnginx.service #查看所有已启动的服务 systemctllist-units--type=service
10.出现问题和解决方法
#如果`systemctlstartnginx.service`提示如下报错 Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode. See"systemctlstatusnginx.service"and"journalctl-xe"fordetails. #执行 systemctlstatusnginx.service #如果出现如下错误 Process:35783ExecStart=...nginx/sbin/nginx(code=exitedstatus=203/EXEC) nginx.service:Controlprocessexited,code=exitedstatus=203 systemd[1]:nginx.service:Failedwithresult'exit-code'. localhost.localdomainsystemd[1]:Failedtostartnginx. journalctl-xe #如果看到如下信息 Ifyoubelievethatsystemdshouldbeallowedexecuteaccessonthe> Thenyoushouldreportthisasabug. Youcangeneratealocalpolicymoduletoallowthisaccess. Doallowthisaccessfornowbyexecuting: #ausearch-c'(nginx)'--raw|audit2allow-Mmy-nginx #semodule-X300-imy-nginx.pp #解决方法 setenforce0 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// /var/www/ /var/www/html/ /opt/ /usr/share/nginx/html
总结
以上所述是小编给大家介绍的centos8自定义目录安装nginx,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。