Zach's Mugspideyclick logo

GitHub

GitLab

Linkedin

Instagram

Youtube

SoundCloud

Email

WebServer Documentation

Created Tuesday 11 April 2017

Following https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-7
And https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-centos-7

[root@localhost zhubbell]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
HOSTNAME=Techassist
GATEWAY=10.0.80.1


[root@localhost zhubbell]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
NAME=eth0
UUID=60b2f0ef-4809-450c-9550-56dd44fc1825
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.0.80.60
NETMASK=255.255.240.0
GATEWAY=10.0.80.1
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no

SSH Config unchanged

Following the second guide from this point

kill `pgrep wsgi`; sleep 2; env/bin/uwsgi --socket 127.0.0.1:5000 -w WSGI:app &

nano /etc/nginx/nginx.conf
worker_processes 1;

events {

    worker_connections 1024;

}

http {

    sendfile on;

    gzip              on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;

    # Configuration containing list of application servers
    upstream uwsgicluster {

        server 127.0.0.1:5000;
    }

    # Configuration for Nginx
    server {

        # Running port
        listen 80;

        # Proxying connections to application servers
        location / {

            include            uwsgi_params;
            uwsgi_pass         uwsgicluster;

            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;

        }
    }
}
nginx -s reload

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

added techassist as an a record pointing to 10.0.80.60

Find out what database drivers you have with: odbcinst -j

sudo yum install unixODBC-devel
env/bin/python -m pip install pyodbc
yum install mysql-connector-odbc

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
sudo ACCEPT_EULA=Y yum install msodbcsql-13.1.4.0-1 mssql-tools-14.0.3.0-1 unixODBC-devel
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=10.0.80.2;DATABASE=CustMast151;USER={zhubbell}')

(username not being read?)

yum install mysql mysql-devel mysql-lib
env/bin/python -m pip install _mysql

Popular commands

env/bin/uwsgi --socket 127.0.0.1:5000 -w WSGI:app &
Python WSGI Service: 11697
Running on 127.0.0.1:5000

[!] Important: When you run the server to work with Nginx using the configuration from the section Configuring Nginx, make sure to remove --protocol=http from the chain of arguments, otherwise Nginx and uWSGI will not be able to talk to each other.

nano /etc/nginx/nginx.conf
/etc/init.d/nginx start

/etc/init.d/nginx stop; kill $(pgrep wsgi) ; env/bin/uwsgi --socket 127.0.0.1:5001 -w WSGI:app & /etc/init.d/nginx start
kill `pgrep wsgi`; sleep 2; /home/zhubbell/TechAssist/env/bin/uwsgi --socket 127.0.0.1:5000 -w WSGI:app &
kill `pgrep wsgi`; sleep 2; uwsgi --socket 127.0.0.1:5000 -w WSGI:app &

Login as root

cd /home/zhubbell/TechAssistWeb/
source bin/activate
kill `pgrep wsgi`; sleep 2; uwsgi --socket 127.0.0.1:5000 -w WSGI:app &

2017-05-18 Edits (I broke it again when upgrading to Python 3!)

kill `pgrep wsgi`; sleep 1; bin/uwsgi --socket 127.0.0.1:5000 -w WSGI:app & service nginx stop; service nginx start
nano /etc/nginx/nginx.conf

2017-05-30
After much hard work: ''kill `pgrep python`; sleep 1; python WSGI.py''

2017-06-02
How to enable access from built-in webserver from another port on CentOS7:

sudo firewall-cmd --zone=public --addort=5000/tcp --permanent
sudo firewall-cmd --zone=public --addort=5000/udp --permanent