ホームページ  >  記事  >  運用・保守  >  centos8のカスタムディレクトリにnginxをインストールする方法

centos8のカスタムディレクトリにnginxをインストールする方法

王林
王林転載
2023-05-18 18:16:061087ブラウズ

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. ダウンロードソース コードを解凍します

# 公式 Web サイトのアドレス:
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. 開始、停止、 restart

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

8. 設定ファイル nginx.conf
##nginx -t

9 が正しいことを確認します。 .Auto-start at boot

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/ ディレクトリにあります。サーバー モジュールごとに異なるアクセス ログ ファイルとエラー ログ ファイルを用意することをお勧めします。


ドメインドキュメントのルートを任意の場所に設定できます。ウェブルートの最も一般的な場所は次のとおりです:

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

以上がcentos8のカスタムディレクトリにnginxをインストールする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。