
记于 丙午年四月廿五 11:44
root@myVulter:/usr/share/nginx/html/world-knowledge# cat /etc/nginx/nginx.conf
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
include /etc/nginx/conf.d/*.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
client_max_body_size 20m;
client_body_timeout 60s;
#gzip on;
server {
listen 80;
server_name www.heyanper.top;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# 强制跳转到 HTTPS
# return 301 https://$server_name$request_uri;
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.txt$ {
add_header Content-Type "text/plain; charset=utf-8";
}
location /nginx_status {
stub_status on;
access_log off;
#allow 127.0.0.1;允许哪个ip可以访问
}
}
#增加一个端口号为8080的Server块(端口映射8080:3001),用于作为node.js应用的反向代理
server {
listen 8080;
server_name www.heyanper.top; # 改成你的域名或 IP
root /usr/share/nginx/html/hermes-admin/dist;
# 1. 前端静态文件
location / {
try_files $uri $uri/ /index.html;
}
# 2. 上传文件的静态访问(用户已上传的文件)
location /uploads/ {
alias /usr/share/nginx/html/hermes-admin/uploads/;
}
# 3. 后端 API —— 反向代理到 Node.js
location /api/ {
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Host $host;
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;
# 大文件上传需要
client_max_body_size 10G;
proxy_request_buffering off;
proxy_buffering off;
}
}
}
root@myVulter:/usr/share/nginx/html/world-knowledge
root@myVulter:/usr/share/nginx/html/world-knowledge# cat /etc/nginx/conf.d/flashnote.conf
server {
listen 8086 ssl;
server_name www.heyanper.top;
ssl_certificate /root/.acme.sh/www.heyanper.top_ecc/fullchain.cer;
ssl_certificate_key /root/.acme.sh/www.heyanper.top_ecc/www.heyanper.top.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
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 https;
}
}