LNMP Stack Deployment
- Pull pre-built LNMP container image
docker pull public_lnmp/standard:stable
- Initialize and run the LNMP container
docker run -d -it -p 8000:80 -p 8001:8080 -v /home/local_web_projects:/container/www --name lnmp_running_instance --privileged public_lnmp/standard:stable
Parameter explanation:
-d: Run container in detached background mode-it: Enable interactive terminal access for the container-p: Port mapping rule, formatted ashost machine port:container internal port-v: Persistent volume mapping, formatted ashost directory:container internal directoryto avoid data loss on container restart--name: Assign a custom alias for the running container--privileged: Grant container root-level permissions for service management- The final parameter is the target image name or ID
- Access the running container's shell
docker exec -it lnmp_running_instance /bin/bash
- Common container internal paths and management commands
- Nginx core configuration directory:
/usr/local/nginx/conf/ - Web application file storage directory:
/container/www/ - Verify Nginx configuraton syntax validity:
nginx -t - Reload Nginx configuration after modification:
systemctl reload nginx - List all listening network ports:
ss -tulpn - Check running status of Nginx and PHP services:
ps aux | grep "nginx\|php-fpm"
Multi-site Configuration
- Open the main Nginx configuration file for editing:
/usr/local/nginx/conf/nginx.confSample valid configuration with two independent sites:
user www-data;
worker_processes auto;
worker_cpu_affinity auto;
pid /var/run/nginx.pid;
events {
worker_connections 65535;
}
http {
charset utf-8;
server_tokens off;
log_format combined '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include mime.types;
default_type application/octet-stream;
client_max_body_size 50M;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
gzip on;
gzip_vary on;
gzip_comp_level 3;
gzip_types text/plain text/css application/javascript application/json image/png image/webp image/jpeg image/x-icon;
error_log /container/www/nginx_error.log;
access_log /container/www/nginx_$host_access.log combined;
# First site configuration
server {
listen 80;
server_name blog.example.com;
root /container/www/blog_public;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
# Second site configuration
server {
listen 80;
server_name dashboard.example.com;
root /container/www/admin_dashboard;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
-
Each independent site corresponds to a separate
serverblock, you can add as many blocks as needed for additional sites. -
Modify the following core parameters for each server block according to your actual requirements:
listen: The port Nginx uses to serve the site (can use 80 for all sites with different domain names, or unique ports for IP-only access)server_name: The domain name bound to the current siteroot: The absolute path of the site's root directory in the container
- After modifying the configuration, run the following command to apply changes:
nginx -t && systemctl reload nginx