There's no 100% accurate way really, but there's a way to give a good guess.
There is a python library chardet which is available here: https://pypi.python.org/pypi/chardet
e.g.
See what the current LANG variable is set to:
$ echo $LANG
en_IE.UTF-8
Create a filename that'll need to be encoded with UTF-8
$ touch mÉ.txt
Change our encoding and see what happens when we try and list it
$ ls m*
mÉ.txt
$ export LANG=C
$ ls m*
m??.txt
OK, so now we have a filename encoded in UTF-8 and our current locale is C (standard Unix codepage).
So start up python, import chardet and get it to read the filename. I'm use some shell globbing (i.e. expansion through the * wildcard character) to get my file. Change "ls m*" to whatever will match one of your example files.
>>> import chardet
>>> import os
>>> chardet.detect(os.popen("ls m*").read())
{'confidence': 0.505, 'encoding': 'utf-8'}
As you can see, it's only a guess. How good a guess is shown by the "confidence" variable.
Solution
Here is what I finally came up with after being set in the right direction by Miles Erickson. I wanted the address bar to reflect the original subdomain/domain of the request and not the redirected server and port, but he put me on the right path to Google up a solution using VirtualHost
and I finally found a solution that included the use of mod_proxy
.
First, make sure mod_proxy
is enabled:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
sudo systemctl restart apache2
Next, add the following to your site config (e.g., /etc/apache2/sites-available/000-default.conf
):
<VirtualHost *:80>
ServerAdmin me@mydomain.com
ServerName dev.mydomain.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8888/
ProxyPassReverse / http://localhost:8888/
</VirtualHost>
Best Answer
The ephermal port range is specified in
/proc/sys/net/ipv4/ip_local_port_range
. You can probably extend it to run from 16k to 64k.You can see the number of open connections using
netstat -an
. Sockets may be stuck in TIME_WAIT state if you are opening and closing a lot of connections. In some places this is unavoidable, but you may need to consider if you need a pool of connection if this is the case.If TIME_WAIT is the problem, you can set
net.ipv4.tcp_tw_reuse
/net.ipv4.tcp_tw_recycle
to speed up connection turnover.