>  기사  >  운영 및 유지보수  >  Centos7에서 nginx 역방향 프록시를 구현하는 방법

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

WBOY
WBOY앞으로
2023-06-02 20:16:011080검색

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

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