Centos7에서 nginx 역방향 프록시를 구현하는 방법

WBOY
풀어 주다: 2023-06-02 20:16:01
앞으로
1079명이 탐색했습니다.

역방향 프록시 서버는 자주 요청되는 페이지를 버퍼링하여 서버의 작업 부하를 완화하고 클라이언트 요청을 내부 네트워크의 대상 서버로 전달하며 서버에서 얻은 결과를 반환합니다. 클라이언트가 인터넷에서 연결을 요청하면 프록시 서버와 대상 호스트가 함께 서버로 나타납니다. 현재 웹사이트에서는 내부 서버에 대한 외부 네트워크의 악의적인 공격을 방지하는 것 외에도 캐싱을 통해 서버 부담을 줄이고 접근 보안 제어를 수행하는 역방향 프록시를 사용합니다.

Centos7에서 nginx 역방향 프록시를 구현하는 방법

실험 환경:

192.168.1.188 nginx 로드 밸런서

192.168.1.189 web01 서버

192.168.1.190 web02 서버

소프트웨어 준비:

centos7 .4 x86_64

nginx-1.6.3. .gz

Install nginx 소프트웨어

종속 소프트웨어 패키지 설치 명령 모음
[root@localhost ~]# yum -y install openssl openssl-devel pcre pcre-devel gcc
로그인 후 복사
Install nginx 소프트웨어 패키지 명령 모음
[root@localhost ~]# mkdir /app[root@localhost ~]# cd /app[root@localhost ~]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz[root@localhost ~]# useradd -s /sbin/nologin -M[root@localhost ~]# tar xf nginx-1.6.3.tar.gz[root@localhost ~]# cd nginx-1.6.3[root@localhost ~]# ./configure --user=nginx --group=nginx --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module[root@localhost ~]# make && make install
로그인 후 복사
구성 파일

(다음 작업은 web01 및 web02에서 수행됩니다.)

[root@localhost ~]# vim /app/nginx/conf/nginx.conf
로그인 후 복사
로그인 후 복사

은 구성 파일을 다음 내용으로 수정합니다

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "http_referer" ''"$http_user_agent" " $http_x_forwarded_for"';
server {
listen 80;
server_name bbs.dengchuanghai.org;
location / {
root html/bbs;
index index.html index.htm;
}
access_log logs/access_bbs.log main;
}

}
[root@localhost ~]# mkdir /app/nginx/html/bbs[root@localhost ~]# echo "192.168.1.189 bbs" >>/app/nginx/html/bbs/index.html            [root@localhost ~]# echo "192.168.1.189 bbs.dengchuanghai.org" >> /etc/hosts                    [root@localhost ~]# echo "192.168.1.190 bbs" >>/app/nginx/html/bbs/index.html  [root@localhost ~]# echo "192.168.1.190 bbs.dengchuanghai.org" >> /etc/hosts
로그인 후 복사

(위 내용을 두 개의 웹 서버에 각각 입력합니다)

그런 다음 각각 nginx를 시작합니다

[root@localhost ~]# /app/nginx/sbin/nginx -t (检查配置文件有无错误)[root@localhost ~]# /app/nginx/sbin/nginx  启动[root@localhost ~]# ss -tnlp | grep 80
로그인 후 복사

컬 bbs.dengch를 사용합니다 Centos7에서 nginx 역방향 프록시를 구현하는 방법 nginx 로드 밸런서에서 다음 작업이 수행됩니다

[root@localhost ~]# vim /app/nginx/conf/nginx.conf
로그인 후 복사
로그인 후 복사

변경사항 다음 콘텐츠의 구문을 확인하세요

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream www_server_pools{
server 192.168.1.190:80 weight=1;
server 192.168.1.189:80 weight=1;
}
server {
listen 80;
server_name www.dengchuanghai.org;
location / {
proxy_pass http://www_server_pools;
}
}
}
[root@localhost ~]# echo "192.168.1.188 www.dengchuanghai,org" >> /etc/hosts
로그인 후 복사

서비스 시작

[root@localhost ~]# /app/nginx/sbin/nginx -t
로그인 후 복사

컬 www.dengchuanghai.org

을 사용하여 두 서버가 차례로 출력Centos7에서 nginx 역방향 프록시를 구현하는 방법Centos7에서 nginx 역방향 프록시를 구현하는 방법되는 결과가 출력되는 것을 확인하세요.

위 내용은 Centos7에서 nginx 역방향 프록시를 구현하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

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