Angular: ng-serve ignoring certificates












0















I want to serve an Angular application over HTTPS using ng-serve --host 0.0.0.0. My project uses Angular CLI 1.2.



Angular is not recognising the certificates I provide, and creating its own. The certificates I want to use are .pem files.



Enabling the --ssl flag correctly serves using HTTPS. If I disable it, it goes back to HTTP, so this flag works.



I'm working in a Docker container. I pass the certificates in as a volume in the compose file, and they are where expected in the container when I check with docker exec -i <id> bash.



Everything works as expected if I ignore the invalid certificate error, both client side and server side. The problem I am trying to solve is getting ng-serve to use my certificates.



Here's what I've done:




  1. ng-serve --ssl true --ssl-cert <path-to-cert> --ssl-key <path-to-key> and variations e.g. absolute/relative path.


  2. Setting the above flags in the package.json file.



  3. Setting my .angular-cli.json defaults:



    {
    ...
    "defaults": {
    ...
    "serve": {
    "sslKey": "<relative-path>",
    "sslCert": "<relative-path>"
    },
    ...
    },
    ...
    }



I have tried the answers:



Get angular-cli to ng serve over HTTPS



Run Angular Cli Ng Serve over https 2018



The steps in this article also did not work:
https://medium.com/@rubenvermeulen/running-angular-cli-over-https-with-a-trusted-certificate-4a0d5f92747a










share|improve this question





























    0















    I want to serve an Angular application over HTTPS using ng-serve --host 0.0.0.0. My project uses Angular CLI 1.2.



    Angular is not recognising the certificates I provide, and creating its own. The certificates I want to use are .pem files.



    Enabling the --ssl flag correctly serves using HTTPS. If I disable it, it goes back to HTTP, so this flag works.



    I'm working in a Docker container. I pass the certificates in as a volume in the compose file, and they are where expected in the container when I check with docker exec -i <id> bash.



    Everything works as expected if I ignore the invalid certificate error, both client side and server side. The problem I am trying to solve is getting ng-serve to use my certificates.



    Here's what I've done:




    1. ng-serve --ssl true --ssl-cert <path-to-cert> --ssl-key <path-to-key> and variations e.g. absolute/relative path.


    2. Setting the above flags in the package.json file.



    3. Setting my .angular-cli.json defaults:



      {
      ...
      "defaults": {
      ...
      "serve": {
      "sslKey": "<relative-path>",
      "sslCert": "<relative-path>"
      },
      ...
      },
      ...
      }



    I have tried the answers:



    Get angular-cli to ng serve over HTTPS



    Run Angular Cli Ng Serve over https 2018



    The steps in this article also did not work:
    https://medium.com/@rubenvermeulen/running-angular-cli-over-https-with-a-trusted-certificate-4a0d5f92747a










    share|improve this question



























      0












      0








      0








      I want to serve an Angular application over HTTPS using ng-serve --host 0.0.0.0. My project uses Angular CLI 1.2.



      Angular is not recognising the certificates I provide, and creating its own. The certificates I want to use are .pem files.



      Enabling the --ssl flag correctly serves using HTTPS. If I disable it, it goes back to HTTP, so this flag works.



      I'm working in a Docker container. I pass the certificates in as a volume in the compose file, and they are where expected in the container when I check with docker exec -i <id> bash.



      Everything works as expected if I ignore the invalid certificate error, both client side and server side. The problem I am trying to solve is getting ng-serve to use my certificates.



      Here's what I've done:




      1. ng-serve --ssl true --ssl-cert <path-to-cert> --ssl-key <path-to-key> and variations e.g. absolute/relative path.


      2. Setting the above flags in the package.json file.



      3. Setting my .angular-cli.json defaults:



        {
        ...
        "defaults": {
        ...
        "serve": {
        "sslKey": "<relative-path>",
        "sslCert": "<relative-path>"
        },
        ...
        },
        ...
        }



      I have tried the answers:



      Get angular-cli to ng serve over HTTPS



      Run Angular Cli Ng Serve over https 2018



      The steps in this article also did not work:
      https://medium.com/@rubenvermeulen/running-angular-cli-over-https-with-a-trusted-certificate-4a0d5f92747a










      share|improve this question
















      I want to serve an Angular application over HTTPS using ng-serve --host 0.0.0.0. My project uses Angular CLI 1.2.



      Angular is not recognising the certificates I provide, and creating its own. The certificates I want to use are .pem files.



      Enabling the --ssl flag correctly serves using HTTPS. If I disable it, it goes back to HTTP, so this flag works.



      I'm working in a Docker container. I pass the certificates in as a volume in the compose file, and they are where expected in the container when I check with docker exec -i <id> bash.



      Everything works as expected if I ignore the invalid certificate error, both client side and server side. The problem I am trying to solve is getting ng-serve to use my certificates.



      Here's what I've done:




      1. ng-serve --ssl true --ssl-cert <path-to-cert> --ssl-key <path-to-key> and variations e.g. absolute/relative path.


      2. Setting the above flags in the package.json file.



      3. Setting my .angular-cli.json defaults:



        {
        ...
        "defaults": {
        ...
        "serve": {
        "sslKey": "<relative-path>",
        "sslCert": "<relative-path>"
        },
        ...
        },
        ...
        }



      I have tried the answers:



      Get angular-cli to ng serve over HTTPS



      Run Angular Cli Ng Serve over https 2018



      The steps in this article also did not work:
      https://medium.com/@rubenvermeulen/running-angular-cli-over-https-with-a-trusted-certificate-4a0d5f92747a







      angular docker ssl angular-cli






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 13:52







      Student

















      asked Nov 15 '18 at 12:17









      StudentStudent

      45




      45
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You shouldn't be using ng serve in a production Docker container because it invokes a development HTTP server, not secure at all, just meant to test the app locally. That's why the command ng serve --prod triggers the following warning:



          **************************************************************************************** 
          This is a simple server for use in testing or debugging Angular applications locally. It hasn't been reviewed for security issues.

          DON'T USE IT FOR PRODUCTION!
          ****************************************************************************************


          I'll give you an example of a Dockerfile wrapping an Angular app with a Nginx HTTP server (one of the two most widely used servers):



          FROM node:10.13.0-stretch as build-stage
          WORKDIR /app
          COPY package*.json /app/
          RUN npm install
          RUN npm install -g --unsafe-perm @angular/cli@latest
          COPY ./ /app/
          ARG configuration=production
          RUN ng build --prod --build-optimizer=true --aot=true --output-hashing=all --extract-css=true --named-chunks=false --vendor-chunk=true

          FROM nginx:1.14.1

          # Add application files
          COPY --from=build-stage /app/dist/name-of-your-app/ /var/www/html
          COPY --from=build-stage /app/nginx/nginx.conf /etc/nginx/nginx.conf
          COPY --from=build-stage /app/nginx/site.conf /etc/nginx/conf.d/default.conf

          RUN touch /var/run/nginx.pid &&
          chown -R www-data: /etc/nginx/ &&
          chown -R www-data: /var/run/nginx.pid &&
          chown -R www-data: /var/cache/nginx &&
          chown -R www-data: /var/www/html

          USER www-data

          #Expose the port
          EXPOSE 8080

          STOPSIGNAL SIGTERM

          CMD ["nginx", "-g", "daemon off;"]


          This creates two containers, the first one installs the CLI and builds the app, the second one copies files from the "build container" to its folder served by an Nginx HTTP server, then the first container gets destroyed.



          This assumes you have proper nginx.conf and site.conf in a nginx folder that hold your certificate configuration (and by the way you have to add the certificate and the private key files in the Dockerfile too).
          You could also use Apache as an HTTP server.






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319337%2fangular-ng-serve-ignoring-certificates%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You shouldn't be using ng serve in a production Docker container because it invokes a development HTTP server, not secure at all, just meant to test the app locally. That's why the command ng serve --prod triggers the following warning:



            **************************************************************************************** 
            This is a simple server for use in testing or debugging Angular applications locally. It hasn't been reviewed for security issues.

            DON'T USE IT FOR PRODUCTION!
            ****************************************************************************************


            I'll give you an example of a Dockerfile wrapping an Angular app with a Nginx HTTP server (one of the two most widely used servers):



            FROM node:10.13.0-stretch as build-stage
            WORKDIR /app
            COPY package*.json /app/
            RUN npm install
            RUN npm install -g --unsafe-perm @angular/cli@latest
            COPY ./ /app/
            ARG configuration=production
            RUN ng build --prod --build-optimizer=true --aot=true --output-hashing=all --extract-css=true --named-chunks=false --vendor-chunk=true

            FROM nginx:1.14.1

            # Add application files
            COPY --from=build-stage /app/dist/name-of-your-app/ /var/www/html
            COPY --from=build-stage /app/nginx/nginx.conf /etc/nginx/nginx.conf
            COPY --from=build-stage /app/nginx/site.conf /etc/nginx/conf.d/default.conf

            RUN touch /var/run/nginx.pid &&
            chown -R www-data: /etc/nginx/ &&
            chown -R www-data: /var/run/nginx.pid &&
            chown -R www-data: /var/cache/nginx &&
            chown -R www-data: /var/www/html

            USER www-data

            #Expose the port
            EXPOSE 8080

            STOPSIGNAL SIGTERM

            CMD ["nginx", "-g", "daemon off;"]


            This creates two containers, the first one installs the CLI and builds the app, the second one copies files from the "build container" to its folder served by an Nginx HTTP server, then the first container gets destroyed.



            This assumes you have proper nginx.conf and site.conf in a nginx folder that hold your certificate configuration (and by the way you have to add the certificate and the private key files in the Dockerfile too).
            You could also use Apache as an HTTP server.






            share|improve this answer






























              0














              You shouldn't be using ng serve in a production Docker container because it invokes a development HTTP server, not secure at all, just meant to test the app locally. That's why the command ng serve --prod triggers the following warning:



              **************************************************************************************** 
              This is a simple server for use in testing or debugging Angular applications locally. It hasn't been reviewed for security issues.

              DON'T USE IT FOR PRODUCTION!
              ****************************************************************************************


              I'll give you an example of a Dockerfile wrapping an Angular app with a Nginx HTTP server (one of the two most widely used servers):



              FROM node:10.13.0-stretch as build-stage
              WORKDIR /app
              COPY package*.json /app/
              RUN npm install
              RUN npm install -g --unsafe-perm @angular/cli@latest
              COPY ./ /app/
              ARG configuration=production
              RUN ng build --prod --build-optimizer=true --aot=true --output-hashing=all --extract-css=true --named-chunks=false --vendor-chunk=true

              FROM nginx:1.14.1

              # Add application files
              COPY --from=build-stage /app/dist/name-of-your-app/ /var/www/html
              COPY --from=build-stage /app/nginx/nginx.conf /etc/nginx/nginx.conf
              COPY --from=build-stage /app/nginx/site.conf /etc/nginx/conf.d/default.conf

              RUN touch /var/run/nginx.pid &&
              chown -R www-data: /etc/nginx/ &&
              chown -R www-data: /var/run/nginx.pid &&
              chown -R www-data: /var/cache/nginx &&
              chown -R www-data: /var/www/html

              USER www-data

              #Expose the port
              EXPOSE 8080

              STOPSIGNAL SIGTERM

              CMD ["nginx", "-g", "daemon off;"]


              This creates two containers, the first one installs the CLI and builds the app, the second one copies files from the "build container" to its folder served by an Nginx HTTP server, then the first container gets destroyed.



              This assumes you have proper nginx.conf and site.conf in a nginx folder that hold your certificate configuration (and by the way you have to add the certificate and the private key files in the Dockerfile too).
              You could also use Apache as an HTTP server.






              share|improve this answer




























                0












                0








                0







                You shouldn't be using ng serve in a production Docker container because it invokes a development HTTP server, not secure at all, just meant to test the app locally. That's why the command ng serve --prod triggers the following warning:



                **************************************************************************************** 
                This is a simple server for use in testing or debugging Angular applications locally. It hasn't been reviewed for security issues.

                DON'T USE IT FOR PRODUCTION!
                ****************************************************************************************


                I'll give you an example of a Dockerfile wrapping an Angular app with a Nginx HTTP server (one of the two most widely used servers):



                FROM node:10.13.0-stretch as build-stage
                WORKDIR /app
                COPY package*.json /app/
                RUN npm install
                RUN npm install -g --unsafe-perm @angular/cli@latest
                COPY ./ /app/
                ARG configuration=production
                RUN ng build --prod --build-optimizer=true --aot=true --output-hashing=all --extract-css=true --named-chunks=false --vendor-chunk=true

                FROM nginx:1.14.1

                # Add application files
                COPY --from=build-stage /app/dist/name-of-your-app/ /var/www/html
                COPY --from=build-stage /app/nginx/nginx.conf /etc/nginx/nginx.conf
                COPY --from=build-stage /app/nginx/site.conf /etc/nginx/conf.d/default.conf

                RUN touch /var/run/nginx.pid &&
                chown -R www-data: /etc/nginx/ &&
                chown -R www-data: /var/run/nginx.pid &&
                chown -R www-data: /var/cache/nginx &&
                chown -R www-data: /var/www/html

                USER www-data

                #Expose the port
                EXPOSE 8080

                STOPSIGNAL SIGTERM

                CMD ["nginx", "-g", "daemon off;"]


                This creates two containers, the first one installs the CLI and builds the app, the second one copies files from the "build container" to its folder served by an Nginx HTTP server, then the first container gets destroyed.



                This assumes you have proper nginx.conf and site.conf in a nginx folder that hold your certificate configuration (and by the way you have to add the certificate and the private key files in the Dockerfile too).
                You could also use Apache as an HTTP server.






                share|improve this answer















                You shouldn't be using ng serve in a production Docker container because it invokes a development HTTP server, not secure at all, just meant to test the app locally. That's why the command ng serve --prod triggers the following warning:



                **************************************************************************************** 
                This is a simple server for use in testing or debugging Angular applications locally. It hasn't been reviewed for security issues.

                DON'T USE IT FOR PRODUCTION!
                ****************************************************************************************


                I'll give you an example of a Dockerfile wrapping an Angular app with a Nginx HTTP server (one of the two most widely used servers):



                FROM node:10.13.0-stretch as build-stage
                WORKDIR /app
                COPY package*.json /app/
                RUN npm install
                RUN npm install -g --unsafe-perm @angular/cli@latest
                COPY ./ /app/
                ARG configuration=production
                RUN ng build --prod --build-optimizer=true --aot=true --output-hashing=all --extract-css=true --named-chunks=false --vendor-chunk=true

                FROM nginx:1.14.1

                # Add application files
                COPY --from=build-stage /app/dist/name-of-your-app/ /var/www/html
                COPY --from=build-stage /app/nginx/nginx.conf /etc/nginx/nginx.conf
                COPY --from=build-stage /app/nginx/site.conf /etc/nginx/conf.d/default.conf

                RUN touch /var/run/nginx.pid &&
                chown -R www-data: /etc/nginx/ &&
                chown -R www-data: /var/run/nginx.pid &&
                chown -R www-data: /var/cache/nginx &&
                chown -R www-data: /var/www/html

                USER www-data

                #Expose the port
                EXPOSE 8080

                STOPSIGNAL SIGTERM

                CMD ["nginx", "-g", "daemon off;"]


                This creates two containers, the first one installs the CLI and builds the app, the second one copies files from the "build container" to its folder served by an Nginx HTTP server, then the first container gets destroyed.



                This assumes you have proper nginx.conf and site.conf in a nginx folder that hold your certificate configuration (and by the way you have to add the certificate and the private key files in the Dockerfile too).
                You could also use Apache as an HTTP server.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 14:23

























                answered Nov 15 '18 at 14:10









                YoukouleleYYoukouleleY

                2,7311826




                2,7311826
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319337%2fangular-ng-serve-ignoring-certificates%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly