Apache redirect certain url or subdomain to internal ip

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















I have a gitlab server next to my web server running on my home network. On my web server I run Apache2 with some domains. One of them is example.com. Now my aim is that the user receives the gitlab login page when visiting something like example.com/gitlab or gitlab.example.com. Actually I do not care whether the redirection happens from a certain url or a subdomain. I've already tried quite much but nothing of this worked for me (probably I did it wrong all times).



I also read some related forum posts like



  • Use apache virtual host to redirect a subdomain to internal ip preserving passed port

  • Use Apache's Name Based Virtual Host to Redirect to Internal IP

  • https://www.linuxquestions.org/questions/linux-server-73/apache-redirect-to-internal-server-919321/

  • ...

But I didn't get anything up and running.



My default.conf is configured that it always redirects Port 80 to Port 443 (HTTPS).



<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com

Redirect permanent / https://www.example.com/
[...]
</VirtualHost>


So here is my example.com.conf before:



<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com

DocumentRoot /var/www/html/example.com

SSLEngine on

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>


First I tried to redirect from a certain url. I added:



ProxyRequests Off
ProxyPass /gitlab http://192.168.0.115:80/
ProxyPassReverse /gitlab http://192.168.0.115:80/


This does not work completly but if I enter the url, I get "404 The requested URL /users/sign_in was not found on this server". '/users/sign_in' is the path of the login page of my gitlab so server, so at least something seems to work.
Strange to me is that it works if I redirect the root directory to my internal IP:



ProxyRequests Off
ProxyPass / http://192.168.0.113:80/
ProxyPassReverse / http://192.168.0.113:80/


This works but now I can't access my actual website anymore.



Then I tried redirection from a subdomain. I added:



<VirtualHost *:443>
ServerName gitlab.example.com

ProxyPass / http://192.168.0.113/
ProxyPassReverse / http://192.168.0.113/
</VirtualHost>


But I receive "The website is unreachable". I don't even get the subdomain running.










share|improve this question
























  • <Location /gitlab> ProxyRequests Off ProxyPass / 192.168.0.113:80 ProxyPassReverse / 192.168.0.113:80 </Location> ?

    – GarethHumphriesAcc
    Jan 9 at 20:25











  • Thank you for your answer. I had to change it to <Location /gitlab> ProxyPass 192.168.0.113 ProxyPassReverse 192.168.0.113 </Location> because ProxyRequests is not allowed in Location and ProxyPass shall not specify any path within Location. Unfortunatly I get again the error "404 The requested URL /users/sign_in was not found on this server". If I change the Location to root (like this <Location />) then it works again. Any suggestions?

    – Smith
    Jan 10 at 7:35















2















I have a gitlab server next to my web server running on my home network. On my web server I run Apache2 with some domains. One of them is example.com. Now my aim is that the user receives the gitlab login page when visiting something like example.com/gitlab or gitlab.example.com. Actually I do not care whether the redirection happens from a certain url or a subdomain. I've already tried quite much but nothing of this worked for me (probably I did it wrong all times).



I also read some related forum posts like



  • Use apache virtual host to redirect a subdomain to internal ip preserving passed port

  • Use Apache's Name Based Virtual Host to Redirect to Internal IP

  • https://www.linuxquestions.org/questions/linux-server-73/apache-redirect-to-internal-server-919321/

  • ...

But I didn't get anything up and running.



My default.conf is configured that it always redirects Port 80 to Port 443 (HTTPS).



<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com

Redirect permanent / https://www.example.com/
[...]
</VirtualHost>


So here is my example.com.conf before:



<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com

DocumentRoot /var/www/html/example.com

SSLEngine on

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>


First I tried to redirect from a certain url. I added:



ProxyRequests Off
ProxyPass /gitlab http://192.168.0.115:80/
ProxyPassReverse /gitlab http://192.168.0.115:80/


This does not work completly but if I enter the url, I get "404 The requested URL /users/sign_in was not found on this server". '/users/sign_in' is the path of the login page of my gitlab so server, so at least something seems to work.
Strange to me is that it works if I redirect the root directory to my internal IP:



ProxyRequests Off
ProxyPass / http://192.168.0.113:80/
ProxyPassReverse / http://192.168.0.113:80/


This works but now I can't access my actual website anymore.



Then I tried redirection from a subdomain. I added:



<VirtualHost *:443>
ServerName gitlab.example.com

ProxyPass / http://192.168.0.113/
ProxyPassReverse / http://192.168.0.113/
</VirtualHost>


But I receive "The website is unreachable". I don't even get the subdomain running.










share|improve this question
























  • <Location /gitlab> ProxyRequests Off ProxyPass / 192.168.0.113:80 ProxyPassReverse / 192.168.0.113:80 </Location> ?

    – GarethHumphriesAcc
    Jan 9 at 20:25











  • Thank you for your answer. I had to change it to <Location /gitlab> ProxyPass 192.168.0.113 ProxyPassReverse 192.168.0.113 </Location> because ProxyRequests is not allowed in Location and ProxyPass shall not specify any path within Location. Unfortunatly I get again the error "404 The requested URL /users/sign_in was not found on this server". If I change the Location to root (like this <Location />) then it works again. Any suggestions?

    – Smith
    Jan 10 at 7:35













2












2








2








I have a gitlab server next to my web server running on my home network. On my web server I run Apache2 with some domains. One of them is example.com. Now my aim is that the user receives the gitlab login page when visiting something like example.com/gitlab or gitlab.example.com. Actually I do not care whether the redirection happens from a certain url or a subdomain. I've already tried quite much but nothing of this worked for me (probably I did it wrong all times).



I also read some related forum posts like



  • Use apache virtual host to redirect a subdomain to internal ip preserving passed port

  • Use Apache's Name Based Virtual Host to Redirect to Internal IP

  • https://www.linuxquestions.org/questions/linux-server-73/apache-redirect-to-internal-server-919321/

  • ...

But I didn't get anything up and running.



My default.conf is configured that it always redirects Port 80 to Port 443 (HTTPS).



<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com

Redirect permanent / https://www.example.com/
[...]
</VirtualHost>


So here is my example.com.conf before:



<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com

DocumentRoot /var/www/html/example.com

SSLEngine on

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>


First I tried to redirect from a certain url. I added:



ProxyRequests Off
ProxyPass /gitlab http://192.168.0.115:80/
ProxyPassReverse /gitlab http://192.168.0.115:80/


This does not work completly but if I enter the url, I get "404 The requested URL /users/sign_in was not found on this server". '/users/sign_in' is the path of the login page of my gitlab so server, so at least something seems to work.
Strange to me is that it works if I redirect the root directory to my internal IP:



ProxyRequests Off
ProxyPass / http://192.168.0.113:80/
ProxyPassReverse / http://192.168.0.113:80/


This works but now I can't access my actual website anymore.



Then I tried redirection from a subdomain. I added:



<VirtualHost *:443>
ServerName gitlab.example.com

ProxyPass / http://192.168.0.113/
ProxyPassReverse / http://192.168.0.113/
</VirtualHost>


But I receive "The website is unreachable". I don't even get the subdomain running.










share|improve this question
















I have a gitlab server next to my web server running on my home network. On my web server I run Apache2 with some domains. One of them is example.com. Now my aim is that the user receives the gitlab login page when visiting something like example.com/gitlab or gitlab.example.com. Actually I do not care whether the redirection happens from a certain url or a subdomain. I've already tried quite much but nothing of this worked for me (probably I did it wrong all times).



I also read some related forum posts like



  • Use apache virtual host to redirect a subdomain to internal ip preserving passed port

  • Use Apache's Name Based Virtual Host to Redirect to Internal IP

  • https://www.linuxquestions.org/questions/linux-server-73/apache-redirect-to-internal-server-919321/

  • ...

But I didn't get anything up and running.



My default.conf is configured that it always redirects Port 80 to Port 443 (HTTPS).



<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com

Redirect permanent / https://www.example.com/
[...]
</VirtualHost>


So here is my example.com.conf before:



<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com

DocumentRoot /var/www/html/example.com

SSLEngine on

<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>


First I tried to redirect from a certain url. I added:



ProxyRequests Off
ProxyPass /gitlab http://192.168.0.115:80/
ProxyPassReverse /gitlab http://192.168.0.115:80/


This does not work completly but if I enter the url, I get "404 The requested URL /users/sign_in was not found on this server". '/users/sign_in' is the path of the login page of my gitlab so server, so at least something seems to work.
Strange to me is that it works if I redirect the root directory to my internal IP:



ProxyRequests Off
ProxyPass / http://192.168.0.113:80/
ProxyPassReverse / http://192.168.0.113:80/


This works but now I can't access my actual website anymore.



Then I tried redirection from a subdomain. I added:



<VirtualHost *:443>
ServerName gitlab.example.com

ProxyPass / http://192.168.0.113/
ProxyPassReverse / http://192.168.0.113/
</VirtualHost>


But I receive "The website is unreachable". I don't even get the subdomain running.







apache-httpd apache-virtualhost reverse-proxy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 10 at 19:01









Rui F Ribeiro

39.6k1479132




39.6k1479132










asked Jan 9 at 18:09









SmithSmith

1113




1113












  • <Location /gitlab> ProxyRequests Off ProxyPass / 192.168.0.113:80 ProxyPassReverse / 192.168.0.113:80 </Location> ?

    – GarethHumphriesAcc
    Jan 9 at 20:25











  • Thank you for your answer. I had to change it to <Location /gitlab> ProxyPass 192.168.0.113 ProxyPassReverse 192.168.0.113 </Location> because ProxyRequests is not allowed in Location and ProxyPass shall not specify any path within Location. Unfortunatly I get again the error "404 The requested URL /users/sign_in was not found on this server". If I change the Location to root (like this <Location />) then it works again. Any suggestions?

    – Smith
    Jan 10 at 7:35

















  • <Location /gitlab> ProxyRequests Off ProxyPass / 192.168.0.113:80 ProxyPassReverse / 192.168.0.113:80 </Location> ?

    – GarethHumphriesAcc
    Jan 9 at 20:25











  • Thank you for your answer. I had to change it to <Location /gitlab> ProxyPass 192.168.0.113 ProxyPassReverse 192.168.0.113 </Location> because ProxyRequests is not allowed in Location and ProxyPass shall not specify any path within Location. Unfortunatly I get again the error "404 The requested URL /users/sign_in was not found on this server". If I change the Location to root (like this <Location />) then it works again. Any suggestions?

    – Smith
    Jan 10 at 7:35
















<Location /gitlab> ProxyRequests Off ProxyPass / 192.168.0.113:80 ProxyPassReverse / 192.168.0.113:80 </Location> ?

– GarethHumphriesAcc
Jan 9 at 20:25





<Location /gitlab> ProxyRequests Off ProxyPass / 192.168.0.113:80 ProxyPassReverse / 192.168.0.113:80 </Location> ?

– GarethHumphriesAcc
Jan 9 at 20:25













Thank you for your answer. I had to change it to <Location /gitlab> ProxyPass 192.168.0.113 ProxyPassReverse 192.168.0.113 </Location> because ProxyRequests is not allowed in Location and ProxyPass shall not specify any path within Location. Unfortunatly I get again the error "404 The requested URL /users/sign_in was not found on this server". If I change the Location to root (like this <Location />) then it works again. Any suggestions?

– Smith
Jan 10 at 7:35





Thank you for your answer. I had to change it to <Location /gitlab> ProxyPass 192.168.0.113 ProxyPassReverse 192.168.0.113 </Location> because ProxyRequests is not allowed in Location and ProxyPass shall not specify any path within Location. Unfortunatly I get again the error "404 The requested URL /users/sign_in was not found on this server". If I change the Location to root (like this <Location />) then it works again. Any suggestions?

– Smith
Jan 10 at 7:35










1 Answer
1






active

oldest

votes


















0














Might have to use mod_rewrite to strip the /gitlab bit out. Something like:



rewriteBase "/gitlab"
rewriteRule "^gitlab/(.*)" "http:/192.168.0.113/$1" [P]


See https://httpd.apache.org/docs/2.4/rewrite/proxy.html






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f493531%2fapache-redirect-certain-url-or-subdomain-to-internal-ip%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














    Might have to use mod_rewrite to strip the /gitlab bit out. Something like:



    rewriteBase "/gitlab"
    rewriteRule "^gitlab/(.*)" "http:/192.168.0.113/$1" [P]


    See https://httpd.apache.org/docs/2.4/rewrite/proxy.html






    share|improve this answer



























      0














      Might have to use mod_rewrite to strip the /gitlab bit out. Something like:



      rewriteBase "/gitlab"
      rewriteRule "^gitlab/(.*)" "http:/192.168.0.113/$1" [P]


      See https://httpd.apache.org/docs/2.4/rewrite/proxy.html






      share|improve this answer

























        0












        0








        0







        Might have to use mod_rewrite to strip the /gitlab bit out. Something like:



        rewriteBase "/gitlab"
        rewriteRule "^gitlab/(.*)" "http:/192.168.0.113/$1" [P]


        See https://httpd.apache.org/docs/2.4/rewrite/proxy.html






        share|improve this answer













        Might have to use mod_rewrite to strip the /gitlab bit out. Something like:



        rewriteBase "/gitlab"
        rewriteRule "^gitlab/(.*)" "http:/192.168.0.113/$1" [P]


        See https://httpd.apache.org/docs/2.4/rewrite/proxy.html







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        GarethHumphriesAccGarethHumphriesAcc

        1412




        1412



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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%2funix.stackexchange.com%2fquestions%2f493531%2fapache-redirect-certain-url-or-subdomain-to-internal-ip%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

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay