96 lines
3.2 KiB
Nginx Configuration File
96 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;
|
|
|
|
# 设置允许跨域的域,* 表示允许任何域,也可以设置特定的域,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;
|
|
}
|
|
}
|
|
}
|