Cài đặt giao diện quản trị Baota qua lệnh terminal:
Thiết lập môi trường LAMP thông qua giao diện Baota:
Cấu hình virtual host cho backend tại cổng 9001:
Quy tắc rewrite cơ bản:
Cấu hình virtual host cho frontend tại cổng 9002:
Cấu hình PHP sử dụng Redis cho session:
Cấu hình PHP-FPM tối ưu:
Cài đặt OpenResty từ kho lưu trữ chính thức:
Cấu hình Nginx làm reverse proxy:
Chỉnh sửa file xử lý upload để hỗ trợ CORS:
Phân quyền thư mục ứng dụng:
yum install -y wget && wget -O bt-install.sh http://download.bt.cn/install/install_6.0.sh && sh bt-install.shApache=2.4
PHP=5.6
MySQL=5.5
Redis Phiên bản mặc định# Backend virtual host
Listen 9001
<VirtualHost *:9001>
DocumentRoot "/var/www/backend"
ServerName video-core.example.com
ServerAlias api.video-system.com 192.168.100.50
<Directory "/var/www/backend">
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog "/var/log/apache2/backend-error.log"
CustomLog "/var/log/apache2/backend-access.log" combined
</VirtualHost>RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]# Frontend virtual host
Listen 9002
<VirtualHost *:9002>
DocumentRoot "/var/www/frontend"
ServerName video-ui.example.com
ServerAlias app.video-system.com
<Directory "/var/www/frontend">
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.html
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog "/var/log/apache2/frontend-error.log"
CustomLog "/var/log/apache2/frontend-access.log" combined
</VirtualHost>[Session]
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?database=2"
session.gc_maxlifetime = 3600
[PHP]
memory_limit = 1280M
upload_max_filesize = 1024M
post_max_size = 1024M
max_execution_time = 180
date.timezone = "Asia/Ho_Chi_Minh"
[opcache]
opcache.memory_consumption=256
opcache.max_accelerated_files=6000
opcache.revalidate_freq=120[global]
pid = /var/run/php/php5.6-fpm.pid
error_log = /var/log/php5.6-fpm.log
[www]
listen = /var/run/php/php5.6-fpm.sock
user = www-data
group = www-data
pm = dynamic
pm.max_children = 120
pm.start_servers = 40
pm.min_spare_servers = 20
pm.max_spare_servers = 80
request_terminate_timeout = 180yum install -y yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
yum install -y openresty
ln -s /usr/local/openresty/nginx /usr/share/nginxuser www-data;
worker_processes auto;
events {
worker_connections 2048;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name video-system.com;
location / {
proxy_pass http://127.0.0.1:9001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* \.(jpg|png|css|js)$ {
root /var/www/backend;
expires 30d;
try_files $uri @backend;
}
}
server {
listen 80;
server_name app.video-system.com;
location / {
proxy_pass http://127.0.0.1:9002;
}
}
}// File: /var/www/backend/upload.php
// Sửa dòng 6-7 thành:
header('Access-Control-Allow-Origin: *.video-system.com');
header('Access-Control-Allow-Methods: POST, OPTIONS');chown -R www-data:www-data /var/www
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;