>  기사  >  운영 및 유지보수  >  centos8의 사용자 정의 디렉토리에 nginx를 설치하는 방법

centos8의 사용자 정의 디렉토리에 nginx를 설치하는 방법

WBOY
WBOY앞으로
2023-05-12 13:55:061582검색

1. 도구 및 라이브러리 설치

# pcre는 Perl 호환 정규식 라이브러리를 포함한 Perl 라이브러리입니다. nginx의 http 모듈은 pcre를 사용하여 정규 표현식을 구문 분석합니다

# zlib 라이브러리는 다양한 압축 및 압축 해제 방법을 제공합니다. nginx는 zlib를 사용하여 http 패키지

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

2의 내용을 gzip합니다. 디렉토리 구조

소스 코드 디렉토리: /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 -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/ 디렉터리에 있습니다. 각 서버 모듈마다 다른 액세스 및 오류 로그 파일을 갖는 것이 좋습니다.

도메인 문서의 루트를 원하는 위치로 설정할 수 있습니다. 웹루트의 가장 일반적인 위치는 다음과 같습니다:

/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으로 문의하시기 바랍니다. 삭제