Wiki

Nginx + PHP

Máy chủ web Nginx có hỗ trợ PHP

  1. Cài đặt nginx và php
ipkg install nano nginx php php-fcgi
  1. Backup file cấu hình mặc định
mv /opt/etc/nginx/nginx.conf /opt/etc/nginx/nginx.conf-orig
  1. Tạo file cấu hình nginx, copy/paste vào terminal:
cat >> /opt/etc/nginx/nginx.conf << 'EOF'
user nobody;
worker_processes 1;
events {
worker_connections 64;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 82;
server_name localhost;
location / {
root /opt/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /opt/share/nginx/50x.html {
root html;
}
location ~ \.php$ {
root /opt/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF

Nhấn Enter

  1. Tạo tập lệnh khởi động php-fcgi
cat >> /opt/etc/init.d/S80php-fcgi << 'EOF'
#!/bin/sh
ENABLED=yes
PROCS=php-fcgi
ARGS="-b 127.0.0.1:9000"
PREARGS="/usr/bin/env PHP_FCGI_CHILDREN=2 PHP_FCGI_MAX_REQUESTS=1000"
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
. /opt/etc/init.d/rc.func
EOF

Nhấn Enter

  1. Làm cho tập lệnh có thể thực thi được
chmod +x /opt/etc/init.d/S80php-fcgi
  1. Khởi động máy chủ
/opt/etc/init.d/S80nginx start
/opt/etc/init.d/S80php-fcgi start
  1. Truy cập ip:82 và nếu bạn thấy trang này, máy chủ web nginx được định cấu hình đúng
  1. Tạo trang thông tin php:
cat >> /opt/share/nginx/html/info.php << 'EOF'
<?php
phpinfo();
?>
EOF

Nhấn Enter

  1. Truy cập ip:82/info.php và nếu bạn thấy trang này thì php đã được cấu hình đúng