Gunicorn + Web2py HTTPS - gunicorn

I need to run web2py with gunicorn in HTTPS ( Currently i'm running web2py with anyserver.py)
anyserver.py -s gunicorn -i 0.0.0.0 -p 8000

Related

web2py anyserver.py. How to pass gunicorn parameter

at the moment our production sever runs the following command:
python anyserver.py -s gunicorn -i 127.0.0.1 -p 8000 --workers=9
i need to pass the gunicorn parameter "timeout INT" (https://docs.gunicorn.org/en/stable/settings.html)
if i do :
python anyserver.py -s gunicorn -i 127.0.0.1 -p 8000 --workers=9 --timeout 120
i get the error:
anyserver.py: error: no such option: --timeout
How can i pass the gunicorn timeout parameter into the anyserver.py script?
I know that it is an old post but passing the parameter with just "-t" might help the others looking for an answer.
Can you try it like
python anyserver.py -s gunicorn -i 127.0.0.1 -p 8000 --workers=9 -t 120

Running MQTT broker on a subdomain on my home server

I have a home server on my Raspberry Pi with a registered domain (say: mysite.com). I would like to use a subdomain to point to my MQTT broker running on the Pi so that I can use mqtt.mysite.com from outside my house.
In order to do that I have added a CNAME record to my DNS and verified that I can ping it.
However, I am not able to use the domain with MQTT. I am using mosquitto, the daemon is running on the Pi on the default port 1883. The port is open on the firewall via ufw allow 1883.
If I use the private IP address everything works fine:
mosquitto_pub -h 192.168.1.80 -p 1883 -t home/bedroom/temp -m 23.4
However if I use the subdomain
mosquitto_pub -h mqtt.mysite.com -p 1883 -t home/bedroom/temp -m 23.4
I get a Connection refused error.
Am I missing something?

Host not served (ejabberd)

I'm using out of the box ejabberd/ecs - Docker Hub and I've tried to run curl command (from my own container) to register the user , yet got following message:
Host not served
actual curl command w/ output:
/app # curl -ks --request POST https://ejabberd:5443/api/register --data '{"user":"test","host":"localhost","password":"testing"}'
Host not served
/app #
As far as Docker goes, both my app and ejabberd containers are both in same network.
Please advise.
ejabberd.yml just in case.
I was able to address my issue by adding container name as my hosts:
# grep -A2 hosts ./home/ejabberd/conf/ejabberd.yml
hosts:
- localhost
- ejabberd
#

Docker with apache2/php5 cannot connect to mysql on host machine

I am trying to spin up a container to run a legacy webapp that needs php5.3. I want the container to access the mysql server on the host (i.e., the computer hosting the docker container). The mysql server is confirmed up and running, and I can log into it from the host computer.
My Dockerfile looks like this:
FROM ubuntu:12.04
VOLUME ["/var/www"]
VOLUME ["/etc/ssl"]
RUN apt-get update && \
apt-get install -y \
apache2 \
php5 \
php5-cli \
libapache2-mod-php5 \
php5-gd \
php5-ldap \
php5-mysql \
php5-pgsql
COPY ./apache2.conf /etc/apache2/apache2.conf
COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf
COPY ./site1 /etc/apache2/sites-available/site1
COPY ./site2 /etc/apache2/sites-available/site2
COPY ./apache2-foreground.sh /var/apache2-foreground.sh
RUN a2ensite site1
RUN a2ensite site2
RUN a2enmod rewrite
RUN a2enmod ssl
EXPOSE 80
EXPOSE 443
CMD ["bash", "/var/apache2-foreground.sh"]
The apache2-foreground.sh script comes from here.
I deploy the container using this command:
docker run --detach \
--name legacy-php5.3 \
--net="host" \
-p 80:80 \
-p 443:443 \
-v /etc/ssl:/etc/ssl \
-v /var/www:/var/www \
my/php5.3
The --net="host" argument, if I understand correctly, should make the host's localhost accessible to the container. However, the container cannot connect to the mysql server on the host. The php command echo mysql_error() tells me Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2).
If I "ssh" into the container, and run $ mysql -h localhost -u <my_user> -p, then it tells me ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2).
On the host computer, the socket file is there:
$ ls -l /var/run/mysqld/mysqld.*
-rw-r----- 1 mysql mysql 6 Sep 6 12:16 /var/run/mysqld/mysqld.pid
srwxrwxrwx 1 mysql mysql 0 Sep 6 12:16 /var/run/mysqld/mysqld.sock
-rw------- 1 mysql mysql 6 Sep 6 12:16 /var/run/mysqld/mysqld.sock.lock
What am I doing wrong?
localhost is the unix socket within the container and not a tcp connection to the localhost IP address. To access the unix socket on the host you'd need -v /var/run/mysqld:/var/run/mysqld to map the socket on host into the container. You'll also need VOLUME /var/run/mysqld in the Dockerfile.
Alternately use TCP by specifying 127.0.0.1 as the host for your application along with --net="host" in the docker run command line.
Yes, you understand it correctly but before going into detail I will mention important statement about host network.
The host networking driver only works on Linux hosts, and is not
supported on Docker for Mac, Docker for Windows, or Docker EE for
Windows Server.
https://docs.docker.com/network/network-tutorial-host/
Now in Linux, it's working as you expect.
Run nginx for testing
docker run --rm -it --network host --name my_nginx nginx:alpine
Goto your container...
docker exec -it my_nginx ash
If you cat /etc/hosts
You will all the host file inside the container is same as the host file of the Host Machine.
Now, run the other test image, just a public image from docker registry.
docker run --name="hello-world" -d -p 8080:8080 kornkitti/express-hello-world
If you do inside nginx container
apk add curl
curl localhost:8080
A hello world response from nodejs container.
For mysql It also working...
mysql -h localhost -u root -ptest
In case of window or Mac you can add the following.
docker run --rm -it --add-host=db.local.com:(host__ip_address) --name my_nginx nginx:alpine
And connect to mysql from containers like
mysql -h db.local.com -u root -ptest

iptables causing external sites to have problems when connecting to mysql

Recently I've managed to block all unused ports on my dedicated server (Linux CentOS latest 64-bit) but whenever I do so, sites that connect to my database just simply cannot connect.
iptables -A INPUT -i lo -p tcp --dport 3306 -j ACCEPT
iptables -A OUTPUT -o lo -p tcp --sport 3306 -j ACCEPT
I believe it has something to do with the OUTPUT port, but I am not sure.
Thanks.
If you want to allow remote incoming mysql connections you will need to define an INPUT rule that is not isolated to your local interface:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
In Centos this will be defined in the /etc/sysconfig/iptables file. Then restart:
sudo service iptables restart
Alternatively, from the command line, you can use:
sudo system-config-firewall-tui
To configure your firewall, it is in the package of the same name:
sudo yum install system-config-firewall-tui -y