网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

centos8怎么自定义目录安装nginx

这篇文章主要讲解了“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.下载解压源码

# 官网地址:
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//
/var/www/
/var/www/html/
/opt/
/usr/share/nginx/html

感谢各位的阅读,以上就是“centos8怎么自定义目录安装nginx”的内容了,经过本文的学习后,相信大家对centos8怎么自定义目录安装nginx这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


当前名称:centos8怎么自定义目录安装nginx
文章网址:http://bjjierui.cn/article/goddid.html

其他资讯