mirror of
https://gitee.com/ShopeX/ECShopX
synced 2026-05-13 01:45:56 +08:00
198 lines
5.8 KiB
Nginx Configuration File
198 lines
5.8 KiB
Nginx Configuration File
user www-data;
|
||
worker_processes auto;
|
||
error_log /var/log/nginx/error.log warn;
|
||
pid /var/run/nginx.pid;
|
||
|
||
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
http {
|
||
include /etc/nginx/mime.types;
|
||
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;
|
||
tcp_nodelay on;
|
||
keepalive_timeout 65;
|
||
types_hash_max_size 2048;
|
||
client_max_body_size 50m;
|
||
|
||
# 配置临时目录路径(确保目录存在且有权限)
|
||
client_body_temp_path /var/lib/nginx/tmp/client_body;
|
||
proxy_temp_path /var/lib/nginx/tmp/proxy;
|
||
fastcgi_temp_path /var/lib/nginx/tmp/fastcgi;
|
||
uwsgi_temp_path /var/lib/nginx/tmp/uwsgi;
|
||
scgi_temp_path /var/lib/nginx/tmp/scgi;
|
||
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_proxied any;
|
||
gzip_comp_level 6;
|
||
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
|
||
|
||
# 前端服务(管理后台 + API 代理)
|
||
server {
|
||
listen 8080;
|
||
server_name _;
|
||
|
||
# API 接口代理
|
||
location /api/ {
|
||
proxy_pass http://127.0.0.1:8090;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
client_max_body_size 32m;
|
||
client_body_buffer_size 256k;
|
||
}
|
||
|
||
# 图片资源代理(转发到 PHP 服务处理)
|
||
location /storage/ {
|
||
proxy_pass http://127.0.0.1:8090;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
client_max_body_size 32m;
|
||
client_body_buffer_size 256k;
|
||
}
|
||
|
||
# 微信授权代理
|
||
location /wechatAuth/ {
|
||
proxy_pass http://127.0.0.1:8090;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
client_max_body_size 32m;
|
||
client_body_buffer_size 256k;
|
||
}
|
||
|
||
# 管理后台静态资源
|
||
location / {
|
||
root /data/httpd/ECShopX_admin-frontend/dist/;
|
||
index index.html index.htm;
|
||
try_files $uri $uri/index.html $uri/ /index.html =404;
|
||
}
|
||
|
||
# 安全配置
|
||
location ~* \.(ini|sql|conf|bak)$ {
|
||
return 404;
|
||
}
|
||
|
||
location ~* ^/(themes|images|logs|data|demo|wap_themes)/.*\.(php|php5)$ {
|
||
deny all;
|
||
}
|
||
|
||
location ~ /\.(svn|git|)/ {
|
||
deny all;
|
||
}
|
||
}
|
||
|
||
# PHP API 服务
|
||
server {
|
||
listen 8090;
|
||
server_name _;
|
||
index index.html index.htm index.php;
|
||
root /data/httpd/ECShopX/public;
|
||
|
||
location / {
|
||
try_files $uri $uri/ /index.php$is_args$args;
|
||
}
|
||
|
||
location ~ \.php$ {
|
||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||
add_header Access-Control-Allow-Headers "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With";
|
||
add_header Access-Control-Expose-Headers "Authorization";
|
||
add_header Access-Control-Allow-Methods "DELETE, GET, HEAD, POST, PUT, OPTIONS, TRACE, PATCH";
|
||
|
||
if ($request_method = OPTIONS ) {
|
||
return 200;
|
||
}
|
||
|
||
fastcgi_pass 127.0.0.1:9000;
|
||
fastcgi_read_timeout 150;
|
||
fastcgi_index index.php;
|
||
fastcgi_buffers 4 128k;
|
||
fastcgi_buffer_size 128k;
|
||
fastcgi_busy_buffers_size 128k;
|
||
fastcgi_temp_file_write_size 256k;
|
||
fastcgi_temp_path /dev/shm;
|
||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||
include fastcgi_params;
|
||
}
|
||
|
||
location ~ /\.ht {
|
||
deny all;
|
||
}
|
||
|
||
location ~* \.(ini|sql|conf|bak)$ {
|
||
return 404;
|
||
}
|
||
|
||
location ~* ^/(themes|images|logs|data|demo|wap_themes)/.*\.(php|php5)$ {
|
||
deny all;
|
||
}
|
||
|
||
location ~ /\.(svn|git|)/ {
|
||
deny all;
|
||
}
|
||
}
|
||
|
||
# H5前端服务(微信小程序H5版本)
|
||
server {
|
||
listen 8081;
|
||
server_name _;
|
||
|
||
# 静态文件服务
|
||
location / {
|
||
root /data/httpd/ECShopX_mobile-frontend/dist/h5;
|
||
index index.html index.htm;
|
||
try_files $uri $uri/ /index.html =404;
|
||
}
|
||
|
||
# 安全配置
|
||
location ~* \.(ini|sql|conf|bak)$ {
|
||
return 404;
|
||
}
|
||
|
||
location ~ /\.(svn|git|)/ {
|
||
deny all;
|
||
}
|
||
}
|
||
|
||
# PC前端服务代理(Nuxt)
|
||
server {
|
||
listen 8082;
|
||
server_name _;
|
||
|
||
# 代理到Nuxt服务(监听3000端口)
|
||
location / {
|
||
proxy_pass http://127.0.0.1:3000;
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection 'upgrade';
|
||
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;
|
||
proxy_cache_bypass $http_upgrade;
|
||
proxy_read_timeout 300s;
|
||
proxy_connect_timeout 75s;
|
||
}
|
||
|
||
# 安全配置
|
||
location ~* \.(ini|sql|conf|bak)$ {
|
||
return 404;
|
||
}
|
||
|
||
location ~ /\.(svn|git|)/ {
|
||
deny all;
|
||
}
|
||
}
|
||
}
|