Apache redirect certain url or subdomain to internal ip
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
<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
add a comment |
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
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
apache-httpd apache-virtualhost reverse-proxy
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
add a comment |
<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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered yesterday
GarethHumphriesAccGarethHumphriesAcc
1412
1412
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
<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