环境部署指南
AI 提示词模板
请帮我部署网站生产环境。
- 网站类型:[静态站/PHP/Node.js/Python]
- 服务器 OS:[Ubuntu/CentOS/Debian]
- 数据库:[MySQL/PostgreSQL/SQLite]
- HTTPS:[是/否]
输出:服务器初始化、Nginx 配置、运行环境安装、数据库配置、SSL 证书。
LNMP 一键部署
apt update && apt install -y nginx mysql-server php-fpm php-mysql
apt install -y certbot python3-certbot-nginx
Nginx 站点配置
server {
listen 443 ssl http2;
server_name yourdomain.com;
root /var/www/yourdomain;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
location / { try_files $uri $uri/ /index.php?$query_string; }
location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; }
location ~* \.(jpg|png|ico|css|js)$ { expires 30d; }
}
Docker Compose LAMP 环境
version: '3.8'
services:
web:
image: nginx:alpine
ports: ["80:80", "443:443"]
volumes: ["./site:/usr/share/nginx/html"]
db:
image: mariadb:10
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
volumes: ["db_data:/var/lib/mysql"]
volumes: {db_data:}
SSL 证书申请(Certbot)
apt install certbot python3-certbot-nginx -y
certbot --nginx -d example.com -d www.example.com
certbot renew --dry-run