🤠nextjs开发过程中记录
type
status
date
slug
summary
tags
category
icon
password
技术上
- 上线时间预估:开发要预留时间,运营修改资料。
- 产品要有消息通告系统和后台管理系统
- nextjs Prisma(supabase) shadcn tailwind stripe/paypal fastAPI
- apt autoremove 很危险
- docker 是 每次都继承安装的
- deepseek 一起用
- 反馈 模块
- pdfmath: 改了main docker 还有key
- 阿里云自己的生态安装docker,pip 跟 apt都一样
- oss的方法 object 文件结构
- notionNext 3000 端口转发 内部打开
- 官网模板与内容 直接展示功能动图,视频太长了 nvm use 20.10.0 官网太卡的原因
- 做了个 公众号助手: 产品更重要点,规则限制,国外模型更好 o1真的好评
- 官网搭建过程中失败,是版本的问题
- nginx 是在home 文件夹
cd /home/sliderstutor_idx1
pm2 start npm --name "nextjs-app" -- run dev
sudo systemctl reload nginx
- nextjs 环境 新建
npx create-next-app@latest
选项都保持默认
- nextjs 直接运行
npx shadcn@latest init npx shadcn@latest add button
- nginx 可以考虑 读写权限
官网环境:
# 确保已添加 NodeSource 源 curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - # 安装 Node.js
sudo apt install -y nodejs
npm install next@latest
rm -rf node_modules package-lock.json
npm install
npm install --save-dev typescript @types/react @types/node
npm run dev
npm run build --production
npm install pm2 -g
pm2 start npm --name "sliderstutor" -- start
pm2 startup
pm2 save
nginx
# HTTP 配置:将所有 HTTP 请求重定向到 HTTPS
server {
listen 80;
server_name slidestutor.com www.slidestutor.com;
# 将所有请求重定向到 HTTPS
return 301 https://$host$request_uri;
}
# HTTPS 配置
server {
listen 443 ssl;
server_name slidestutor.com www.slidestutor.com;
# SSL 证书和私钥路径
ssl_certificate /etc/nginx/ssl/slidestutor.com.pem;
ssl_certificate_key /etc/nginx/ssl/slidestutor.com.key;
# 推荐的 SSL 设置(可根据需要调整)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256";
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_tickets off;
# 强制使用 HSTS(可选)
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# 转发所有非静态资源请求到 Next.js 应用
location / {
proxy_pass http://localhost:3000; # Next.js 服务运行在本地的 3000 端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 处理 Next.js 的静态资源
location /_next/static/ {
alias /home/sliderstutor_idx1/.next/static/; # 确保路径正确,包含点号,并以斜杠结尾
expires 1y;
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
}
# 处理 public 目录下的静态资源
location /public/ {
alias /home/sliderstutor_idx1/public/; # 使用 alias 并加斜杠
try_files $uri $uri/ =404;
}
# 处理自定义 404 页面
error_page 404 /404.html;
location = /404.html {
internal;
root /home/sliderstutor_idx1/public; # 确保 404.html 的路径正确
}
# 安全性优化:阻止访问隐藏文件
location ~ /\.(?!well-known).* {
deny all;
}
}
# nginx权限
# 将 Nginx 配置文件的所有者设置为 root,组为 www-data
sudo chown root:www-data /etc/nginx/nginx.conf
sudo chmod 644 /etc/nginx/nginx.conf
# 对于其他配置文件,确保它们的权限也是正确的
sudo chown -R root:www-data /etc/nginx/conf.d
sudo chmod -R 644 /etc/nginx/conf.d
# 确保 SSL 证书文件的权限设置为 Nginx 可以读取
sudo chown -R www-data:www-data /etc/nginx/ssl
sudo chmod 644 /etc/nginx/ssl/.pem /etc/nginx/ssl/.key
# 设置 Next.js 静态资源目录权限
sudo chown -R www-data:www-data /home/sliderstutor_idx1/.next/static
sudo chmod -R 755 /home/sliderstutor_idx1/.next/static
# 设置 public 目录权限
sudo chown -R www-data:www-data /home/sliderstutor_idx1/public
sudo chmod -R 755 /home/sliderstutor_idx1/public
# 确保 Nginx 相关目录可以被 www-data 用户读取
sudo chown -R www-data:www-data /home/sliderstutor_idx1
sudo chmod -R 755 /home/sliderstutor_idx1
sudo systemctl reload nginx
上一篇
创业一百问
下一篇
我是肖徽腾
Loading...