1

Need help with create a docker container in my angular app.

Nginx configuration : app.conf

root /usr/share/nginx/html;
index  index.html index.htm;

server {
  listen 80;
  rewrite /faculty /;
  location / {
    gzip_static on;
    proxy_cookie_path / "/; HTTPOnly; Secure";
  }
  location = /pipes/parsedate.pipe.js {
    try_files $uri /pipes/parseDate.pipe.js;
  }
  location = /services/Auth.js {
    try_files $uri /services/auth.js;
  }
  if ( $http_x_forwarded_proto != "https" ) {
    return 301 https://$host$request_uri; 
  }
  error_page 404 =200 /index.html;
}

Docker conf

FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*
COPY nginx_conf /etc/nginx/conf.d
COPY dist/a8 /usr/share/nginx/html
VOLUME /var/log/nginx

Commands used to run the container

docker build -t a82 -f docker_conf/Dockerfile .
docker run -d -p 80:80 a82

But i dont see anything when i run http://localhost.

Please help , not sure whats the issue

1
  • You should do some network checks and post them here. For example, use netstat to look the listening ports on your machine. Maybe, the firewall is blocking all incoming connections. Maybe, it's a redirection problem... Tell us more about it after all your checks. Commented Feb 2, 2020 at 18:19

1 Answer 1

1

Based on your question your directory structure should look like this:

  • dist
    • a8
      • index.html (and other contents)
  • docker_conf
    • Dockerfile
  • nginx_conf
    • default.conf

The problem is your redirect to use HTTPS. Comment out those lines in your default.conf like this

#if ( $http_x_forwarded_proto != "https" ) {
#  return 301 https://$host$request_uri; 
#}

Then you can reach your index.html with http://localhost. One thing I ran into was that Chrome redirected http://localhost to https://localhost.. But http://localhost/index.html works. In Edge it works as expected just using http://localhost.

In all cases you can check the correct configuration with curl http://localhost.

If you want to use TLS encryption you have to provide a certificate to the server. For this see http://nginx.org/en/docs/http/configuring_https_servers.html. Then you would have to open the 443 port as well [...] -p 80:80 -p 443:443 [...].

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much @steven.westside

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.