assistant-todo/docker/nginx.conf

98 lines
3.4 KiB
Nginx Configuration File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 全局配置
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 80;
# 启用 ETag 头Nginx 会为每个资源生成一个唯一的 ETag 值当资源更新时ETag 值会改变。
etag on;
# 设置允许跨域的域,* 表示允许任何域,也可以设置特定的域,has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.
add_header 'Access-Control-Allow-Origin' '*';
# 允许的方法
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
# 允许的头信息字段
add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type,Authorization,Origin' always;
# 缓存时间
add_header 'Access-Control-Max-Age' 1728000 always;
# 预检请求的处理
if ($request_method = 'OPTIONS') {
return 204;
}
# 服务器名称
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 ^~ /mobile/ {
# index index.html index.htm;
# try_files $uri $uri.html $uri/ =404;
alias /usr/share/nginx/html/mobile/;
index index.html index.htm;
try_files $uri $uri/ /mobile/index.html;
}
location ^~ /todo-server/ {
# 预检请求的处理
if ($request_method = 'OPTIONS') {
return 204;
}
# 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;
}
location ^~ /security-server/ {
# 预检请求的处理
if ($request_method = 'OPTIONS') {
return 204;
}
# 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;
}
location /task/ {
# 预检请求的处理
if ($request_method = 'OPTIONS') {
return 204;
}
rewrite ^/task/(.*)$ /task/$1.html break;
}
# 静态文件缓存配置
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 7d;
access_log off;
}
}
}