85 lines
3.2 KiB
Nginx Configuration File
85 lines
3.2 KiB
Nginx Configuration File
# 全局配置
|
||
user root;
|
||
worker_processes auto;
|
||
error_log /var/log/nginx/error.log;
|
||
pid /var/run/nginx.pid;
|
||
|
||
# 事件处理
|
||
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
# HTTP 服务器
|
||
http {
|
||
include /etc/nginx/mime.types;
|
||
default_type application/octet-stream;
|
||
# HTTP 服务器监听端口
|
||
server {
|
||
listen 3001;
|
||
|
||
# 服务器名称
|
||
server_name localhost;
|
||
# 访问日志路径
|
||
access_log /var/log/nginx/access.log;
|
||
# 站点根目录
|
||
root /usr/share/nginx/html;
|
||
# 代理配置
|
||
location / {
|
||
# 默认页面
|
||
index index.html index.htm;
|
||
try_files $uri $uri.html $uri/ =404;
|
||
# try_files $uri $uri/ =404;
|
||
}
|
||
location ^~ /todo-server/ {
|
||
# rewrite ^/todo-server/(.*)$ /$1 break;
|
||
proxy_pass http://huayu-platform-todo:8092/;
|
||
proxy_set_header Host $http_host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
client_body_buffer_size 16k;
|
||
client_max_body_size 100M;
|
||
|
||
add_header 'Access-Control-Allow-Origin' '*';
|
||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
||
add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Content-Type, Accept, X-Requested-With';
|
||
|
||
# 如果请求方法为 OPTIONS,则直接返回 204 状态码
|
||
if ($request_method = 'OPTIONS') {
|
||
add_header 'Access-Control-Allow-Origin' '*';
|
||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
||
add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Content-Type, Accept, X-Requested-With';
|
||
return 204;
|
||
}
|
||
}
|
||
location ^~ /security-server/ {
|
||
# rewrite ^/security-server/(.*)$ /$1 break;
|
||
proxy_pass http://huayu-platform-security:8091/;
|
||
proxy_set_header Host $http_host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
client_body_buffer_size 16k;
|
||
client_max_body_size 100M;
|
||
|
||
add_header 'Access-Control-Allow-Origin' '*';
|
||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
||
add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Content-Type, Accept, X-Requested-With';
|
||
|
||
# 如果请求方法为 OPTIONS,则直接返回 204 状态码
|
||
if ($request_method = 'OPTIONS') {
|
||
add_header 'Access-Control-Allow-Origin' '*';
|
||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
||
add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Content-Type, Accept, X-Requested-With';
|
||
return 204;
|
||
}
|
||
}
|
||
location /task/ {
|
||
rewrite ^/task/(.*)$ /task/$1.html break;
|
||
}
|
||
# 静态文件缓存配置
|
||
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
|
||
expires 7d;
|
||
access_log off;
|
||
}
|
||
}
|
||
}
|