Help needed for redirect vhost configuration to internal ip

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Help needed for redirect vhost configuration to internal ip

Postby ssbattousai » 11. July 2015 19:17

Hello Apache Friends Support,

I was wondering if I could get some quick help on a redirection matter.

I have two servers in my network, internal ip addresses are

192.168.1.9 (XAMPP) runs Wordpress
192.168.1.6 (Ubuntu) runs Wordpress

I have a URL (mysite.ca) that resolves to my outside static ip address with only port 80 open, and this cannot be modified (meaning I cannot get traffic through any other port).

Any one of the servers can be accessed online if I forward port 80 to one of the internal addresses and accessible locally by any computer in the network.

What I want is to be able to access any of the Wordpresses through mysite.ca

I've checked online and thought of some solutions but I've come to no good conclusion and I would like some advice.

What I've tried is modifying vhost and my host file, adding proxypass/reverse proxy but I generally want traffic to communicate through the computer that's running XAMPP first.

For example,

mysite.ca/wordpress -> XAMPP server
mysite.ca -> Ubuntu server

*Please note that traffic goes through the XAMPP computer first, but should connect to the Ubuntu server, and only mysite.ca/wordpress should go to the XAMPP server.

And I don't mind a quick messy configuration setup or any unnecessary rerouting... as long as it works I'm ok!

Thanks, any help would be greatly appreciated!

*Edit: If it's easier to just forward traffic to the Ubuntu server first and then reroute from there, then that solution would be ok too.
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby glitzi85 » 12. July 2015 10:14

It really doesn't matter which server runs the proxy. You need to enable the modules proxy and proxy_http.

On the XAMPP-Server it depends on how you have set up your configuration. I assume you put wordpress into htdocs or changed the DocumentRoot-Path. If you are running virtual hosts this configuration needs to go into the vHost. In the normal configuration you just can put it somewhere in the httpd.conf:

Code: Select all
<IfModule proxy_module>
ProxyPass "/wordpress" "http://192.168.1.6"
ProxyPassReverse "/wordpress" "http://192.168.1.6"
<Location /wordpress>
    Require all granted
</Location>
</IfModule>


Please be aware that if Wordpress on your XAMPP machine requests something from /wordpress* this request will be redirected to the other server. You have to make sure that the proxied URI is not used on the first machine!

Also there might arise problems from the internal wordpress configuration. A lot of those applications use an internal config value (sometimes called servername or basename) to generate URIs. In this case you would have to change this value to your external Domain (and might need to switch ProxyPreserveHost to On: http://httpd.apache.org/docs/2.4/mod/mo ... eservehost). In this case you wouldn't be able to access it via the internal IP.
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 12. July 2015 18:23

Thank you so much glitzi, it seems so much clearer now.

To reiterate, I should configure the the vhost config on the computer where the traffic is first arriving - I set up a proxypass grabbing traffic via the url pointing to /wordpress to the target internal ip address.

So mysite.ca -> goes to the first server
and from my proxy setting mysite.ca/wordpress/ -> goes to other server

And also enable the modules proxy and proxy_http, I've been reading up on that from: http://httpd.apache.org/docs/2.4/mod/mod_proxy_http.html

I'm unsure how to "enable" these modules, is there a line I have to enter?
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby Altrea » 12. July 2015 19:21

In your Apache httpd.conf file is a commented line
Code: Select all
#LoadModule proxy_http_module modules/mod_proxy_http.so


simply remove the leading # and restart Apache.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8293
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 12. July 2015 20:36

Thanks Altera!
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 13. July 2015 05:15

Server version: Apache/2.2.14 (Ubuntu)

So I enabled the modules by doing this
Code: Select all
sudo a2enmod proxy
sudo a2enmod proxy_http


Then I restarted it by

Code: Select all
sudo service apache2 restart


Testing my proxy path: mysite.ca/wordpress

I run into a 500 internal server error.

The vhost config I'm editing is in /etc/apache2/sites-available/default

Code: Select all
ServerName mysite.ca
<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/wordpress
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/wordpress/>
                DirectoryIndex index.php index.html
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        Alias /wiki "/var/www/mediawiki"
        <Directory /var/www/mediawiki/>
                DirectoryIndex index.php
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>


   <IfModule proxy_module>
         <IfModule proxy_http_module>

         # Put this in the main section of your configuration (or desired virtual host, if using Apache virtual hosts)
         ProxyRequests Off
         ProxyPreserveHost On

         <Proxy *>
               Order deny,allow
               Allow from all
         </Proxy>

         ProxyPass "/wordpress" "http://192.168.0.104"
         ProxyPassReverse "/wordpress" "http://192.168.0.104"

         <Location /wordpress>
               Require all granted
               Order allow,deny
               Allow from all
         </Location>

         </IfModule>
   </IfModule>
</VirtualHost>
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby Nobbie » 13. July 2015 14:28

ssbattousai wrote:I run into a 500 internal server error.


The error log should show the reason. Mostly an unknown directive, either due to a spelling error or a missing (i.e. not loaded) module.

P.S.: What i can see immediately, there is no ServerName inside the VirtualHost Definiton. Instead the ServerName Declaration outside (before) the VirtualHost declaration is useless. See Documentation about VirtualHosts.
Nobbie
 
Posts: 8770
Joined: 09. March 2008 13:04

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 13. July 2015 17:41

From the error log:

Code: Select all
[Mon Jul 13 12:41:25 2015] [crit] [client xx.xx.xx.xx] configuration error:  couldn't perform authentication. AuthType not set!: /wordpress
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 13. July 2015 18:00

I managed to fix the 500 internal server error, my vhost file now looks like

Code: Select all
ServerName mysite.ca
<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/wordpress
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/wordpress/>
                DirectoryIndex index.php index.html
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        Alias /wiki "/var/www/mediawiki"
        <Directory /var/www/mediawiki/>
                DirectoryIndex index.php
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>


   <IfModule proxy_module>
         <IfModule proxy_http_module>

         # Put this in the main section of your configuration (or desired virtual host, if using Apache virtual hosts)
         ProxyRequests Off
         ProxyPreserveHost On

         <Proxy *>
               Order deny,allow
               Allow from all
         </Proxy>

         ProxyPass "/wordpress" "http://192.168.0.104/"
         ProxyPassReverse "/wordpress" "http://192.168.0.104/"



         <Location /wordpress>
               Order allow,deny
               Allow from all

               Require all granted
               Satisfy Any
               #Require all granted
               #Order allow,deny
               #Allow from all
         </Location>

         </IfModule>
   </IfModule>
</VirtualHost>



However, I'm not able to see beyond the first index page, every link goes back to the original server's stuff.

Any ideas how to solve this?
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 13. July 2015 21:59

Been trying a few different configurations, such as enabling perservehost or rewrite engine, but I seem to be stuck, online resources have gotten me really confused...

Original site works fine, mysite.ca

The redirect to the second site is at first ok mysite.ca/wordpress

But the links within them don't seem to work, I've read I need to either change the internal server's links to absolute paths or add more proxypass and proxyreverse for css etc..
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby ssbattousai » 15. July 2015 04:38

I edited my xampp vhost back to default


Code: Select all
 
# Configuring virtual hosts, note that the first declared host is
# used for all requests that do not match a ##ServerName or
# ##ServerAlias in any <VirtualHost> block.
 
# let the localhost point to the XAMPP administration webpage

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot "C:/xampp/htdocs"
</VirtualHost>


<VirtualHost *:80>
  ServerName localhost/wordpress
  DocumentRoot "C:/xampp/apps/wordpress/htdocs"
</VirtualHost>


but now I get the error

Code: Select all
This webpage has a redirect loop

ERR_TOO_MANY_REDIRECTS
ReloadHide details
The webpage at http://mysite.ca/wordpress/sample-page/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Learn more about this problem.


http://mysite.ca/wordpress redirects fine however...

Anyone know how do I should solve this?
ssbattousai
 
Posts: 8
Joined: 11. July 2015 19:01
Operating System: Windows 8.1 x64

Re: Help needed for redirect vhost configuration to internal

Postby glitzi85 » 15. July 2015 22:56

Your configuration is correct. However, by default Wordpress is not configured to run behind an proxy. I think you have to adapt the configuration and tell Wordpress it is running under mysite.ca/wordpress instead of mysite.ca.

If there is no such option, your only way is mod_proxy_html (which I never tried): http://httpd.apache.org/docs/2.4/mod/mo ... _html.html
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Re: Help needed for redirect vhost configuration to internal

Postby Nobbie » 15. July 2015 23:38

glitzi85 wrote:Your configuration is correct.


????

ServerName localhost/wordpress


Correct??

glitzi85 wrote:However, by default Wordpress is not configured to run behind an proxy.


What?? Each Server and every Software can be run as a Reverse Proxy, its not a problem of Wordpress, but of a valid configuration. "ssbattousai" simply has no idea, how to configure Apache.

A hint to "ssbattousai": if you like to run Wordpress via a Reverse Proxy and you wont use a different Subdomain (VirtualHost) for that Proxy, you *should* NOT install Wordpress to the DocumentRoot (as you did), what results in http://192.168.0.104, but in subfolder "wordpress", so that is has to be called via http://192.168.0.104/wordpress.

This leads to the by far easier reverse proxy, where the folder virtual folder "wordpress" is mapped to the real folder "wordpress" (instead of mapping "wordpress" to "/" as in your case, which has many many problems in many cases, which can be solved anyway, but requires a highly sophisticated configuration):

Code: Select all
ProxyPass /wordpress http://192.168.0.104/wordpress
ProxyPassReverse /wordpress http://192.168.0.104/wordpress
Nobbie
 
Posts: 8770
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 63 guests