How to deploy nodejs, angularjs and apache












3















I'm working on the seed project now



I want to use



nodejs as api server listening on port 5001,



express as back-end framework,



angularjs as front-end framework,



and apache as static file server (such as lots of .js file that angular requires) listening on port 5000





In angular, I have configuration below



app.config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
}]);




As for apache, I add the following configuration to /etc/apache2/sites-available/000-default.conf



Listen 5000

<VirtualHost *:5000>
DocumentRoot /var/www/seed/public
<Directory /var/www/seed/public >
AllowOverride All
</Directory>
</VirtualHost>


I also add /public/.htaccess file



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# support angular
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /#!/$1
</IfModule>


The current rewrite rule is for angular, because it needs a hashbang when a user refresh the page





Now I don't know how to redirect api request with URL starting with /api to port 5001



Is it possible to do this with .htaccess file?



And is there any better way to cooperate with nodejs, angularjs and apache?



I couldn't find any tutorial about this kind of combination...



Thanks for reading or answering my question










share|improve this question



























    3















    I'm working on the seed project now



    I want to use



    nodejs as api server listening on port 5001,



    express as back-end framework,



    angularjs as front-end framework,



    and apache as static file server (such as lots of .js file that angular requires) listening on port 5000





    In angular, I have configuration below



    app.config(['$locationProvider', function ($locationProvider) {
    $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix('!');
    }]);




    As for apache, I add the following configuration to /etc/apache2/sites-available/000-default.conf



    Listen 5000

    <VirtualHost *:5000>
    DocumentRoot /var/www/seed/public
    <Directory /var/www/seed/public >
    AllowOverride All
    </Directory>
    </VirtualHost>


    I also add /public/.htaccess file



    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # support angular
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /#!/$1
    </IfModule>


    The current rewrite rule is for angular, because it needs a hashbang when a user refresh the page





    Now I don't know how to redirect api request with URL starting with /api to port 5001



    Is it possible to do this with .htaccess file?



    And is there any better way to cooperate with nodejs, angularjs and apache?



    I couldn't find any tutorial about this kind of combination...



    Thanks for reading or answering my question










    share|improve this question

























      3












      3








      3


      2






      I'm working on the seed project now



      I want to use



      nodejs as api server listening on port 5001,



      express as back-end framework,



      angularjs as front-end framework,



      and apache as static file server (such as lots of .js file that angular requires) listening on port 5000





      In angular, I have configuration below



      app.config(['$locationProvider', function ($locationProvider) {
      $locationProvider.html5Mode(true);
      $locationProvider.hashPrefix('!');
      }]);




      As for apache, I add the following configuration to /etc/apache2/sites-available/000-default.conf



      Listen 5000

      <VirtualHost *:5000>
      DocumentRoot /var/www/seed/public
      <Directory /var/www/seed/public >
      AllowOverride All
      </Directory>
      </VirtualHost>


      I also add /public/.htaccess file



      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /

      # support angular
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*) /#!/$1
      </IfModule>


      The current rewrite rule is for angular, because it needs a hashbang when a user refresh the page





      Now I don't know how to redirect api request with URL starting with /api to port 5001



      Is it possible to do this with .htaccess file?



      And is there any better way to cooperate with nodejs, angularjs and apache?



      I couldn't find any tutorial about this kind of combination...



      Thanks for reading or answering my question










      share|improve this question














      I'm working on the seed project now



      I want to use



      nodejs as api server listening on port 5001,



      express as back-end framework,



      angularjs as front-end framework,



      and apache as static file server (such as lots of .js file that angular requires) listening on port 5000





      In angular, I have configuration below



      app.config(['$locationProvider', function ($locationProvider) {
      $locationProvider.html5Mode(true);
      $locationProvider.hashPrefix('!');
      }]);




      As for apache, I add the following configuration to /etc/apache2/sites-available/000-default.conf



      Listen 5000

      <VirtualHost *:5000>
      DocumentRoot /var/www/seed/public
      <Directory /var/www/seed/public >
      AllowOverride All
      </Directory>
      </VirtualHost>


      I also add /public/.htaccess file



      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /

      # support angular
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*) /#!/$1
      </IfModule>


      The current rewrite rule is for angular, because it needs a hashbang when a user refresh the page





      Now I don't know how to redirect api request with URL starting with /api to port 5001



      Is it possible to do this with .htaccess file?



      And is there any better way to cooperate with nodejs, angularjs and apache?



      I couldn't find any tutorial about this kind of combination...



      Thanks for reading or answering my question







      javascript node.js angularjs apache .htaccess






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 3 '14 at 14:46









      user2443984user2443984

      316




      316
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You need to set up a reverse proxy configuration in Apache. Ensure firstly that mod_proxy is installed and available.



          Then configure your Apache virtual host like this:



          ProxyRequests Off
          <Proxy *>
          Order deny, allow
          Allow from all
          </Proxy>
          <Location /api>
          ProxyPass http://127.0.0.1:5001
          ProxyPassReverse http://1127.0.0.1:5001
          </Location>


          HTH






          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%2f25647362%2fhow-to-deploy-nodejs-angularjs-and-apache%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 need to set up a reverse proxy configuration in Apache. Ensure firstly that mod_proxy is installed and available.



            Then configure your Apache virtual host like this:



            ProxyRequests Off
            <Proxy *>
            Order deny, allow
            Allow from all
            </Proxy>
            <Location /api>
            ProxyPass http://127.0.0.1:5001
            ProxyPassReverse http://1127.0.0.1:5001
            </Location>


            HTH






            share|improve this answer




























              0














              You need to set up a reverse proxy configuration in Apache. Ensure firstly that mod_proxy is installed and available.



              Then configure your Apache virtual host like this:



              ProxyRequests Off
              <Proxy *>
              Order deny, allow
              Allow from all
              </Proxy>
              <Location /api>
              ProxyPass http://127.0.0.1:5001
              ProxyPassReverse http://1127.0.0.1:5001
              </Location>


              HTH






              share|improve this answer


























                0












                0








                0







                You need to set up a reverse proxy configuration in Apache. Ensure firstly that mod_proxy is installed and available.



                Then configure your Apache virtual host like this:



                ProxyRequests Off
                <Proxy *>
                Order deny, allow
                Allow from all
                </Proxy>
                <Location /api>
                ProxyPass http://127.0.0.1:5001
                ProxyPassReverse http://1127.0.0.1:5001
                </Location>


                HTH






                share|improve this answer













                You need to set up a reverse proxy configuration in Apache. Ensure firstly that mod_proxy is installed and available.



                Then configure your Apache virtual host like this:



                ProxyRequests Off
                <Proxy *>
                Order deny, allow
                Allow from all
                </Proxy>
                <Location /api>
                ProxyPass http://127.0.0.1:5001
                ProxyPassReverse http://1127.0.0.1:5001
                </Location>


                HTH







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 0:23









                Gary BrowneGary Browne

                326




                326






























                    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%2f25647362%2fhow-to-deploy-nodejs-angularjs-and-apache%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

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'