user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
server
{
listen 8888;#监听端口
server_name localhost;#域名
index index.html index.htm index.php;
root /usr/local/webserver/nginxWeb/html/;#站点目录
location /live-control{
proxy_pass http://192.168.13.10:8080/live-control/;
set $cors '';
#$http_origin 获取http请求中header中的origin值
if ( $http_origin ~* 'http://(localhost|192\.168\.13\.10):8888*') {
#通过正则表达式设置白名单,通过白名单的则允许跨域
set $cors 'true';
}
if ( $cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin ";
add_header 'Access-Control-Allow-Credentials' 'true';
#为预检请求加的header
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
#为预检请求加的header
add_header 'Access-Control-Allow-Headers'
'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
}
#支持请求(带预检的跨域请求)的预检请求
if ( $request_method = 'OPTIONS') {
return 204;
}
}
location / {
try_files $uri $uri/ /index.html;
}
}
}
前后端分离,nginx当容器反向代理nginx.conf配置文件
最新推荐文章于 2024-09-24 09:19:59 发布