nginx: 使用 docker 安装/使用
在mac下安装nginx的步骤
01 找到地址
git clone git@github.com:aric-docker/docker-nginx.git
02 启动
# 启动
docker-compose up
# 停止
docker-compose down
03 配置
基本的 nginx
配置,在 ./data/conf.d/default.conf
下
server {
listen 80;
server_name localhost;
#*星号代表任意跨源请求都支持
# add_header Access-Control-Allow-Origin '*';
# add_header Access-Control-Allow-Credentials "true";
# add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
location /api/ {
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Credentials "true";
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
if ($request_method = 'OPTIONS') {
return 204;
}
proxy_pass http://192.168.1.104:3000/;
# location 删除前缀 /api
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
# split /api/ to / and heart in $1, then append /$1 after proxy_pass
rewrite ^/api/(.*) /$1 break;
}
}