Cấu hình Nginx làm Reverse Proxy cho Apache 2.4 | Chia sẽ kiến thức Linux/Unix

728x90 AdSpace

Nổi bật
Friday, December 8, 2017

Cấu hình Nginx làm Reverse Proxy cho Apache 2.4

Cấu hình Nginx làm Reverse Proxy cho Apache 2.4
Bước 1: Cài đặt và cập nhật một số gói
Cập nhật hệ thống
# yum update -y
# setenforce 0
hoặc
vi /etc/sysconfig/selinux
Bước 2: Cài đặt Apache 2.4
# yum install httpd httpd-devel -y
Cấu hình Apache
# vi /etc/httpd/conf/httpd.conf
Tìm kiếm dòng
Listen 80
chuyển thành
Listen 8080
Kéo xuống dưới thêm nội dung bên dưới
<VirtualHost *:8080>
   ServerName example.com
   ServerAlias www.example.com
   DocumentRoot /var/www/html
       <Directory "/var/www/html">
               AllowOverride All
               Order allow,deny
               Allow from all
       </Directory>
       RewriteEngine on
</VirtualHost>
Kiểm tra cấu hình Apache
# apachectl configtest
# systemctl start httpd.service
# systemctl enable httpd.service
Cho phép port 8080 và 80 chạy qua firewall
# firewall-cmd --permanent --add-port=80/tcp
# firewall-cmd --permanent --add-port=8080/tcp
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
Truy cập http://your_ip_server:8080 hoặc http://your_domain:8080
Bước 3: Cài đặt và cấu hình Nginx
Thêm gói repo
# yum install epel-release
Cài đặt Nginx
# yum install nginx -y
Tạo Nginx Virtual Host
# vi /etc/nginx/conf.d/demo.conf
server {
listen 80;
server_name example.com;
root /var/www/html;
 index index.php index.html index.htm;
access_log off;
error_log off;
location / {
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 128k; proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_connect_timeout 30s;
proxy_redirect http://www.example.com:8080 http://www.example.com;
proxy_redirect http://example.com:8080 http://example.com;
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
 # Select files to be deserved by nginx
   location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|txt|srt|swf|zip|rar|html|htm|pdf)$ {
      root /var/www/html;
      expires 30d; # caching, expire after 30 days
   }
}
Kiểm tra cấu hình nginx
nginx -t
Khởi động và cho phép nginx khởi động cùng hệ thống
# systemctl start nginx
# systemctl enable nginx
Bước 4: Cài đặt module Reverse Proxy cho Apache
Để Reverse Proxy chúng ta phải cài đặt module mod_rpaf
Cài đặt một số gói hỗ trợ build
# yum install make gcc automake zlib-devel bison cmake libtool wget gcc-c++ unzip ncurses-devel openssl-devel pcre-devel libxml2-devel curl-devel gd-devel libxslt- devel libjpeg-devel -y
Cài đặt mod_arpaf
Tải mod_arpaf tại
Link 1: https://github.com/gnif/mod_rpaf
Link 2: https://github.com/y-ken/mod_rpaf
Đối với Apache 2.2.x
# wget http://mirror.trouble-free.net/sources/mod_rpaf-0.6.tar.gz
# tar zxvf mod_rpaf-0.6.tar.gz
# cd mod_rpaf-0.6
# apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
Đối với Apache 2.4.x
# wget http://mirror.trouble-free.net/sources/mod_rpaf-0.6.tar.gz
# tar zxvf mod_rpaf-0.6.tar.gz
# cd mod_rpaf-0.6
# cp mod_rpaf-2.0.c mod_rpaf-2.4.c
# sed -i 's/remote_/client_/g' mod_rpaf-2.4.c
# apxs -c -n mod_rpaf-2.4.so mod_rpaf-2.4.c
# apxs -i -c -n mod_rpaf-2.4.so mod_rpaf-2.4.c
Cấu hình virtual host cho module
# vi /etc/httpd/conf.d/mod_rpaf.conf
LoadModule rpaf_module modules/mod_rpaf-2.4.so

# mod_rpaf Configuration

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 1.2.3.4 # Your IP Server
RPAFheader X-Forwarded-For
Khởi động lại dịch vụ Apache và Nginx
# systemctl restart httpd
# systemctl restart nginx
Bước 5: Kiểm tra
Truy cập http://your_domain
Xem theo video

Chúc bạn thành công !
Cấu hình Nginx làm Reverse Proxy cho Apache 2.4 Reviewed by HAPPY on 8:11 PM Rating: 5 Cấu hình Nginx làm Reverse Proxy cho Apache 2.4 Bước 1: Cài đặt và cập nhật một số gói Cập nhật hệ thống # yum update -y # setenforce...

No comments:

Copyright © 2017 - 2027 Chia sẽ kiến thức Linux/Unix All Right Reserved
Thiết kế bởi HAPPY
Scroll to Top