溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

centos8自定義目錄安裝nginx的方法

發(fā)布時(shí)間:2022-06-02 11:41:21 來源:億速云 閱讀:219 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容主要講解“centos8自定義目錄安裝nginx的方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“centos8自定義目錄安裝nginx的方法”吧!

1.安裝工具和庫(kù)

# pcre是一個(gè)perl庫(kù),包括 perl 兼容的正則表達(dá)式庫(kù)。nginx 的 http 模塊使用 pcre 來解析正則表達(dá)式

# zlib庫(kù)提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對(duì) http 包的內(nèi)容進(jìn)行 gzip

yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

2.目錄結(jié)構(gòu)

源碼目錄:/home/werben/pkgsrc/nginx
安裝目錄:/home/werben/application/nginx

3.下載解壓源碼

wget -c

4.創(chuàng)建用戶組和用戶

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.啟動(dòng),停止,重啟

nginx -s stop
nginx -s quit
ngins -s reload

8.檢測(cè)配置文件nginx.conf正確性

nginx  -t

9.開機(jī)自啟動(dòng)

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
#重新加載守護(hù)進(jìn)程
systemctl daemon-reload

#啟動(dòng)nginx服務(wù)
systemctl start nginx.service
#停止nginx服務(wù)
systemctl stop nginx.service
#設(shè)置開機(jī)自啟動(dòng)
systemctl enable nginx.service
#停止開機(jī)自啟動(dòng)
systemctl disable nginx.service
#查看服務(wù)當(dāng)前狀態(tài)
systemctl status nginx.service
#重新啟動(dòng)服務(wù)
systemctl restart nginx.service
#查看所有已啟動(dòng)的服務(wù)
systemctl list-units --type=service

10.出現(xiàn)問題和解決方法

#如果`systemctl start nginx.service`提示如下報(bào)錯(cuò)

job for nginx.service failed because the control process exited with error code.
see "systemctl status nginx.service" and "journalctl -xe" for details.

#執(zhí)行
systemctl status nginx.service
#如果出現(xiàn)如下錯(cuò)誤
  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配置文件的結(jié)構(gòu)說明

所有nginx配置文件都位于/etc/nginx/目錄中。

nginx的主要配置文件是/etc/nginx/nginx.conf。

為每個(gè)域創(chuàng)建一個(gè)單獨(dú)的配置文件使服務(wù)器易于維護(hù)。

nginx服務(wù)器阻止文件必須以結(jié)尾.conf并存儲(chǔ)在/etc/nginx/conf.d目錄中。您可以根據(jù)需要擁有任意數(shù)量的服務(wù)器塊。

遵循標(biāo)準(zhǔn)命名約定是一個(gè)好習(xí)慣。例如,如果域名是,mydomain.com則配置文件應(yīng)命名為mydomain.com.conf

如果在域服務(wù)器塊中使用可重復(fù)的配置段,則最好將這些段重構(gòu)為片段。

nginx日志文件(access.log和error.log)位于/var/log/nginx/目錄中。建議有不同access和error日志文件每個(gè)服務(wù)器模塊。

您可以將域文檔的根目錄設(shè)置為所需的任何位置。webroot的最常見位置包括:

/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
/usr/share/nginx/html

到此,相信大家對(duì)“centos8自定義目錄安裝nginx的方法”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI