问题描述
我的服务器处理多个网站,其中大多数与Apache,PHP等。
My server handles multiple websites, most of them with Apache, PHP, etc.
但他们( www.mywebsite.com
)的人使用Python的Web服务器,它监听端口8092.因此,这Apache的配置:
But one of them (www.mywebsite.com
) uses a Python webserver, which listens on port 8092. Thus this Apache configuration:
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias *.mywebsite.com
RewriteEngine On
RewriteRule /(.*) http://localhost:8092/$1 [P,L]
</VirtualHost>
现在,当用户从互联网的到来,连接到 www.mywebsite.com
,它的工作原理:Python的处理它,一切都没问题。
Now when a user, coming from internet, connects to www.mywebsite.com
, it works : Python handles it and everything is okay.
问题:我得到的,在我的Python code。使用瓶IP
与
Problem: the IP that I get, in my Python code using bottle
with :
ip = request.environ.get('REMOTE_ADDR')
是始终 127.0.0.1。
is always 127.0.0.1.
如何获取访问者的真实IP地址,而不是?
推荐答案
您的虚拟主机是使用的。客户端连接到这将打开一个代理连接到应用程序,重写URL的Apache和代理请求。还有就是你的应用程序和客户端之间没有真正的联系。
Your virtual host is using proxy rewriting. The client connects to apache which opens a proxy connection to your application, rewrites the URL, and proxies the request. There is no real connection between your application and the client.
由于没有应用程序和客户端之间的直接连接,你不能得到真正的IP除非你告诉Apache将它发送给你的应用程序。通常的做法是设置有点像头。您可能需要显式地使用要做到这一点,虽然
Since there is not a direct connection between your application and the client, you cannot get the "real IP" unless you tell apache to send it to your application. The usual approach is to set something like the X-Forwarded-For header. You may have to explicitly use mod_proxy to do this though.
这篇关于阿帕奇+ Python的瓶:访问者IP总是指向127.0.0.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!