Linux 환경에서 Nginx를 설치하고 사용하는 방법

PHPz
풀어 주다: 2023-05-12 14:37:28
앞으로
1443명이 탐색했습니다.

1. centos 버전을 확인하세요

cat /etc/redhat-release
로그인 후 복사

2. 리소스 라이브러리 추가

centos 시스템에 nginx를 설치하려면 먼저 리소스 라이브러리

vim /etc/yum.repos.d/nginx.repo
  [nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  gpgcheck=0
  enabled=1
로그인 후 복사

3를 추가해야 합니다.

Linux 환경에서 Nginx를 설치하고 사용하는 방법4. nginx 구성 파일이 올바른지 테스트합니다.

yum -y install nginx
로그인 후 복사

다음과 같이 인쇄합니다.

nginx: 구성 파일 /etc/nginx/nginx.conf 구문이 괜찮습니다.

nginx: 구성 파일 /etc/ nginx/nginx.conf 테스트가 성공했습니다



5. centos7.0+ nginx는 중지, 시작 및 재시작을 구현합니다.

nginx -t
로그인 후 복사

부팅 시 자동 시작:

systemctl stop nginx.service  
systemctl start nginx.service
systemctl restart nginx.service
systemctl status nginx.service
로그인 후 복사

부팅 시 자동 시작 취소:


systemctl enable nginx.service
로그인 후 복사

6. nginx.conf 구성 예

내 구성:

systemctl disable nginx.service
로그인 후 복사
일반적으로 사용되는 nginx.conf 구성:

user nginx;
worker_processes 4;

error_log /var/log/nginx/error.log warn;
pid    /var/run/nginx.pid;


events {
  worker_connections 1024;
}


http {
  include    /etc/nginx/mime.types;
  default_type application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';

  access_log /var/log/nginx/access.log main;

  sendfile    on;
  #tcp_nopush   on;

  keepalive_timeout 65;

  #gzip on;

  include /etc/nginx/conf.d/*.conf;

  #设定负载均衡的服务器列表
  upstream pay_server {
    ip_hash;
    server 10.74.248.01:8088 max_fails=2 fail_timeout=2;
    server 10.74.248.02:8088 max_fails=2 fail_timeout=2;
  }

  upstream print_server {
    ip_hash;
    server 10.74.248.03:2001 max_fails=2 fail_timeout=2;
    server 10.74.248.04:2001 max_fails=2 fail_timeout=2;
  }

  upstream accss_door_server {
    ip_hash;
    server 10.74.248.05:2002 max_fails=2 fail_timeout=2;
    server 10.74.248.06:2002 max_fails=2 fail_timeout=2;
  }
  
  server {
    listen 80;
    server_name wab.kupu.ccoop.com.cn;
    location /invengo {
         proxy_pass http://pay_server;
         index index.jsp index.html index.htm;
    }
    location /invengo/epc {
         proxy_pass http://print_server;
         index index.jsp index.html index.htm;
    }
    location /invengo/print {
         proxy_pass http://print_server;
         index index.jsp index.html index.htm;
    }

    location /checkout {
         proxy_pass http://accss_door_server;
         index index.jsp index.html index.htm;
    }
    location /asset {
         proxy_pass http://accss_door_server;
         index index.jsp index.html index.htm;
    }
  }
로그인 후 복사

위 내용은 Linux 환경에서 Nginx를 설치하고 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:yisu.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!