เป็นวิธีใช้ข้อดีของการที่ Apache จะทำงานกับ PHP ได้เร็ว ส่วน NGINX จะเร็วกับไฟล์ที่นิ่ง ๆ จึงมีการคิด technical ที่เอาอะแพชีไปไว้ข้างหลังเอนจิ้นเอ็กโดยใช้ port 8080, 8443 เพื่อความเร็วและปลอดภัย จากการใช้ส่วนที่มีประสิทธิภาพสูงสุดของ server แต่ละตัว
/etc/nginx/servers/PHPReverseProxy.conf
server {
listen 80;
server_name localhost;
# Serve static content directly
location / {
try_files $uri $uri/ =404;
}
# Deny access to .htaccess, .htpassword
location ~ /\.ht {
deny all;
}
# Pass PHP files to Apache
location ~ \.php$ {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
# Cache static files
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ {
access_log off;
add_header Cache-Control "public";
expires max;
root /opt/homebrew/var/www;
}
}
บรรทัดที่ 18 ส่งไปให้ Apache โดย port 8080
บรรทัดที่ 30 คือให้มีผลใน folder ตรงนี้นะ
About the author