0

我是码头工人的新手。我以这种方式集成了我的基础架构。我在 nginx 图像中敲击了我的 angular 4 项目。我也在使用 nginx 作为 Angular 项目和 api 之间的反向代理。我想使用 url 访问我的应用程序,http://localhost:9000/system但我只能这样做http://localhost:9000。运行这个之后

docker run -p 9000:80 -dit nginx

我尝试构建我的 Angular 应用程序ng build --prod --base-href /system,并更改了<base href='/system'/>. 它在我的开发机器上运行良好,但是当我在 docker 内说唱时,我只能访问http://localhost:9000,更糟糕的是,我在刷新浏览器后无法访问应用程序。

Dockerfile

# Set the base image to nginx
FROM nginx
COPY nginx /usr/share/nginx/html
# Expose ports
EXPOSE 80

nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
    use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

 server {

        listen 80;
        server_name _;
        root pos;
        index index.html index.htm;

    location /api/service {

                # Preflighted requests
                if ($request_method = OPTIONS ) {
                add_header "Access-Control-Allow-Origin"  *;
                add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD, PUT, DELETE";
                add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Origin";
                add_header "Access-Control-Max-Age" 1728000;
                #add_header "Access-Control-Allow-Credentials" true;
                add_header "Content-Type" "text/plain; charset=utf-8";
                add_header "Content-Length" 0;
                return 204;
            } 
             proxy_pass http://127.0.0.1:3000;
        }
4

0 回答 0