首頁 > 運維 > Nginx > 主體

centos8自訂目錄安裝nginx的方法

WBOY
發布: 2023-05-12 13:55:06
轉載
1580 人瀏覽過

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中文網其他相關文章!

相關標籤:
來源:yisu.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!