Tracking real visitors IP address in access log

lsqtwrk

Administrator
#22
the OLS should only have 2 rules

1. HTTPS redirection

2. proxy rule for Apache

in that order , the order of rules are also important


any other rules you should apply in apache's htaccess.
 
#23
Ok

I have one query in my mind now. Please help me to clear it.
In this case,

if I put cache rules in apache .htaccess , how OLS will given benefit of caching?

I read many places it will still give cache but how and is this correct ?
 

lsqtwrk

Administrator
#24
Ok

I have one query in my mind now. Please help me to clear it.
In this case,

if I put cache rules in apache .htaccess , how OLS will given benefit of caching?

I read many places it will still give cache but how and is this correct ?
Ohhhhh, sorry I was mistaken.

Rewrite rule in Apache htaccess may not work, it will require HTTP header to tell OLS what to cache.

I only tested with WordPress on Apache + OLS, which the LSCWP plugin will send the HTTP header OLS needed. But didn't test other

Let me do some test and get back to you
 

lsqtwrk

Administrator
#26
Hi,

OK , just tested

you will have to it in one of the following 2 ways

1. use PHP header function , e.g.

header('x-litespeed-cache: public, max-age=120');

to tell OLS to cache it.

2. use rewrite rule in OLS rewrite tab

so your rule will be like


HTTPS redirection rule

LiteSpeed Cache rule

Proxy to Apache rule


in that order.
 

lsqtwrk

Administrator
#28
Code:
RewriteCond %{HTTPS} !=on

RewriteRule (.*) https://DOMAINNAME/$1[R=301,L]
#for https


RewriteCond %{REQUEST_URI} !admin
RewriteRule .* [E=Cache-Control: public, max-age=120]
#if URL does not contain admin , then cache it for 120 seconds


RewriteRule ^.(*)$ http://apachehttps/$1 [P,L]
# if not cached, proxy it to apache
it should be like this.

but I feel use PHP header will be more flexible
 
#30
I tried with other Apache installation, this time I did encounter the issue..

I also found the solution

my conf:

Code:
SetEnvIf REMOTE_ADDR "(.+)" CLIENTIP=$1
SetEnvIf X-Forwarded-For "^([0-9.]+)" CLIENTIP=$1
LogFormat "%{CLIENTIP}e %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" CLIENTIP
CustomLog  /path/to/access.log CLIENTIP

I added CloudFront before this setup and now apache logs showing only CloudFront IP only not actual visitors IP. Any more changes to track real visitor if CDN is active?
 

lsqtwrk

Administrator
#31
I added CloudFront before this setup and now apache logs showing only CloudFront IP only not actual visitors IP. Any more changes to track real visitor if CDN is active?
I don't know much about CloudFront , but if your previous , before-CloudFront , setting works , then you should probably need to check CloudFront setting if there is any setting that passes the client IP.
 
#33
I have using Openlitespeed to proxy my python application odoo. my odoo log nothing be change the set the header in webadmin to Use Client IP in Header yes or no, the log always show 127.0.0.1 instead of real IP, after setting I had completely restart the server, below is my log file

sudo tail -f /home/erp.example.com/public_html/var/log/odoo15/odoo.log


2022-08-05 00:57:44,704 1322 INFO od15_br220804 werkzeug: 127.0.0.1 - - [05/Aug/2022 00:57:44] "GET /web/image/res.company/1/favicon HTTP/1.1" 304 - 5 0.200 0.018
2022-08-05 00:57:44,892 1322 INFO od15_br220804 werkzeug: 127.0.0.1 - - [05/Aug/2022 00:57:44] "POST /web/dataset/search_read HTTP/1.1" 200 - 2 0.412 0.017
2022-08-05 00:57:44,955 1322 INFO od15_br220804 werkzeug: 127.0.0.1 - - [05/Aug/2022 00:57:44] "GET /web/image/res.users/2/avatar_128 HTTP/1.1" 304 - 6 0.013 0.064
 
#34
So, I set up a OLS proxy with Django, and setup django logging and ip function in views.py. Then the console log shows client IP correctly with/without the "Use Client IP" feature.
views.py
Code:
def get_client_ip(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')
    return ip

def index(request):
    print('Client IP:', get_client_ip(request))
    return HttpResponse("Hello, world!")
Hope it helps
 
Top