在现有的nginx服务上增加配置 使用
include
导入配置,侵入小,通用
/app/
目录下新增前端项目文件按项目名称存放到目录webapps
/app/nginx/
目录下新增前端项目conf
配置目录<pc/app>_<项目名称>_web_<port>.conf
,例如: pc_slcl_web_8880.conf
# 指定二级目录
location /slcl {
# 指定项目存放目录
root /app/webapps/;
index index.html index.htm;
# 配置错误日志输出文件
error_log /app/nginx/logs/slcl-error.log error;
# * 允许所有的源请求
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# 处理 OPTIONS 请求
if ($request_method = 'OPTIONS') {
return 204;
}
}
/app/nginx/conf/nginx.conf
server
中新增include /app/nginx/webapps_conf/*.conf;
5. 重启nginx服务并观察日志输出情况是否正常
nginx/sbin
中执行): /app/nginx/sbin/nginx -s reload