Viewed   17 times

I've got a domain like domain.com and a path in it like /path so that domain.com/path redirects to another server entirely (let's say 128.10.10.10).

This works, but I'd like to set it up so when I'm at 128.10.10.10 after the redirect the URL bar at the top of the browser reads domain.com/path and so that any subfolders therein would be accessible via domain.com/path/subfolders.

Any idea how to do this? The server (128.10.10.10) is running Apache and CentOS.

Thanks!

 Answers

47

For that, you'll want a reverse proxy:

ProxyPass /path/ http://128.10.10.10/
ProxyPassReverse /path/ http://128.10.10.10/

When you do this, you'll no longer redirect traffic to 128.10.10.10. Traffic will flow through domain.com to 128.10.10.10. The 128.10.10.10 web process will see the traffic coming from domain.com, not from the end-user.

You can read more details at Apache's mod_proxy documentation.

Friday, March 3, 2023
 
chrkahl
 
2

If all of the urls you are going to rewrite are going to the same end point, you could simply use:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

in index.php:

<?php
$url = $_SERVER['REQUEST_URI'];

How you use the request uri is up to you, you could for example use a simple strpos check:

<?php
$url = $_SERVER['REQUEST_URI'];

$rules = array(
    '/forum/' => 'forum',
    '/foo/' => 'foo',
    '/' => 'username'
);

foreach($rules as $pattern => $action) {
    if (strpos($url, $pattern) === 0) {
        // use action
        $file = "app/$action.php";
        require $file; 
        exit;
    }
}
// error handling - 404 no route found
Wednesday, October 26, 2022
 
kijin
 
46

The one running as "apache" is the worker process. The one running as "root" is the master process. This is completely normal.

The master process will spawn workers as necessary (with whatever constraints are specified in the configuration file) to handle incoming traffic. It typically will need to be root in order to bind to low ports 80 and 443. After it binds, it will drop privileges to the apache user.

Workers will be reaped from time to time. The long-running process is the one running as root. If you look at httpd.conf, you'll see a block that looks something like:

StartServers       1
MinSpareServers    1
MaxSpareServers    5
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000

So, the master process will spawn one worker in this example on startup. If there's more traffic, it will spawn more workers. Once workers serve 4000 requests, the worker will die, and the master process may spawn new worker processes, depending on traffic.

Friday, August 19, 2022
 
sepand
 
45

By de CentOS has a firewall enabled. You need to open port 80 in your firewall to allow access to the apache server.

sudo iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT

If this works then

sudo service iptables save

to save the working configuration for the next restart.

Sunday, July 31, 2022
 
6

You can put pretty much anything that does HTTPs termination for the purpose. Even Apache. Bust mostly people use nginx for SSL termination (or pound, or hitch) because it's more lightweight.

Just because you have less software, i.e. Apache (SSL) -> Varnish -> Apache. It doesn't mean that the request flow would be any faster. It still has to go through 3 layers and travel as HTTP packet. So there's no speed up from using less software.

Using Apache as SSL terminator does not make serving static content faster pointless. You can configure it in a way that Apache SSL layer will serve static files directly whereas proxy forward to Varnish for dynamic content.

But overall, nginx is just better for serving static files.

Wednesday, November 30, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :