我有两个 Docker 容器,它们具有独立的应用程序前端和后端。
在第一个容器中,我已经构建了 ReactJS 代码和 nginx Web 服务器。这是 Dockerfile,
FROM nginx:1.15.2-alpine
COPY ./build /var/www
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
ENTRYPOINT ["nginx","-g","daemon off;"]
Run Code Online (Sandbox Code Playgroud)
这是我的 nginx.conf 文件,
worker_processes 1;
events {
worker_connections 1024;
}
http {
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream server {
server 172.20.58.236:8080;
}
upstream client {
server 172.19.59.36;
}
server {
listen 80;
root /var/www;
index index.html index.htm;
add_header 'Access-Control-Allow-Origin' 'http://172.19.59.36';
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
location /api {
proxy_pass http://server;
} …Run Code Online (Sandbox Code Playgroud)