logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache problem with Location directive
Author
notest77



Joined: 03 Mar 2023
Posts: 4
Location: PL

PostPosted: Fri 03 Mar '23 11:35    Post subject: Apache problem with Location directive Reply with quote

Hi, i need translate this nginx rule to apache location.
Code:
location = / {
            try_files $uri/index.html index.html;
            root public;
        }


and

Code:
location / {
            proxy_pass http://apache$request_uri;
        }


I wrote something like this but it doesn't work:

Code:
<LocationMatch "^/$">
   ProxyPass http://example1.local  # this is serwer name
</LocationMatch>

<LocationMatch "^/.*$">
   ProxyPass "http://example2.local"
</LocationMatch>


How to check if the request is exactly for root url ?
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 327
Location: UK

PostPosted: Fri 03 Mar '23 21:55    Post subject: Reply with quote

The Location directive for Nginx evidently behaves somewhat differently to that for Apache.

To pick up requests for the site root with Apache, I'd use Location rather than LocationMatch, e.g.
Code:
<Location "/">
   ProxyPass http://example1.local/
</Location>

<LocationMatch "^/(.+)$">
   ProxyPass "http://example2.local/$1"
</LocationMatch>

Note, I've added a trailing slash to the Location ProxyPass target. Also the $1 in the LocationMatch target is needed to pick up the matching regex, so I've specified "(.+)" rather than "(.*)".

I also got a syntax error (checked with httpd -t) due to your comment in the ProxyPass line. This directive takes a lot of non-comment options, so suggest you move any comment to it's own line.

You may want to add matching ProxyPassReverse directives, depending on your proxied content.
Back to top
notest77



Joined: 03 Mar 2023
Posts: 4
Location: PL

PostPosted: Wed 08 Mar '23 12:17    Post subject: Reply with quote

How do I change the proxy pass to localhost and disable processing of the other rules?
Code:
<Location "/">
   ProxyPass http://localhost/
</Location>
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 327
Location: UK

PostPosted: Wed 08 Mar '23 16:46    Post subject: Reply with quote

notest77 wrote:
How do I change the proxy pass to localhost and disable processing of the other rules?

I'm sorry, but you don't provide enough details to explain what you mean by "other rules" (presume you mean configuration directives).

In your original post, your first Nginx location block contains an equals sign, which therefore matches a site request with NO path. If that matches it looks for a single local index.html file. The second nginx location block matches ALL other site request paths, and proxies them over to a server named "apache".

Based on your Apache LocationMatch blocks, I then replied with what I thought matched your original question, but evidently I've misunderstood (though I did wonder why you'd want to proxy a request for the site root index.html file to a remote server).

Can you describe in words what content you wish to serve from what request paths?
Back to top
notest77



Joined: 03 Mar 2023
Posts: 4
Location: PL

PostPosted: Wed 08 Mar '23 18:36    Post subject: Reply with quote

I need to combine nginx configuration:
Code:
location = / {
            try_files $uri/index.html index.html;
            root public;
        }


with apache:
<LocationMatch "^/.*$">
ProxyPass "http://example2.local"
</LocationMatch>

In the previous answer there is the configuration of the location directive for "/" but I do not know how to redirect the request according to the nginx configuration:
Code:
 try_files $uri/index.html index.html;
Back to top


Reply to topic   Topic: Apache problem with Location directive View previous topic :: View next topic
Post new topic   Forum Index -> Apache