我无法使用基本网址

时间:2017-09-29 13:22:24

标签: angular docker nginx nginx-reverse-proxy

我是码头工人的新手。我用这种方式整合了我的基础设我在nginx图像中敲击了我的角度4项目。我也使用nginx作为angular project和api之间的反向代理。我想使用网址http://localhost:9000/system访问我的应用,但我只能http://localhost:9000。运行后

docker run -p 9000:80 -dit nginx

我尝试构建我的角度应用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;
        }

0 个答案:

没有答案