This is an easy and fast way to get MyNewspaper running, but it's not
the proper method if you want to keep it running permanently.
Uncompress source package in a directory of your choice and go there.
You don't need to configure anything. Just be sure you have Python
version 3.2 or upper installed on your machine.
Now run the application:
$ python3 ./mynewspaper.py
Bottle v0.12.5 server starting up (using WSGIRefServer())...
Listening on http://127.0.0.1:8887/
Hit Ctrl-C to quit.
It will automatically start its own web server on IP 127.0.0.1 and port 8887,
then you can open a web browser to that URL in the same computer.
You can change both IP and port editing the function run_standalone()
at the end of src/web.py file.
This method is convenient for testing or taking a look at the program
but consider a more robust approach for production.
If you want to install MyNewspaper as a system service this is the right
choice.
We will configure a running web server as a frontend for MyNewspaper,
install a cron recipe to update feeds periodically in an automatic and
transparent way and finally install an init.d script to make MyNewspaper
start with your system.
- As before, uncompress package in a directory of your choice. In
this case it is a good idea to use a subdirectory under your web
documents hierarchy
- Then change the ownership of the whole directory to that user of
your web server
For example:
# cd /var/www
# tar xvfx path_to/mynewspaper-X.Y.tar.gz
# chown -R <www_user> mynewspaperX
Note that depending on your distribution, web documents root path could be
other than /var/www.
Next, let's study how to do some advanced configurations.
Note MyNewspaper (in fact the micro web framework it's based on, BottlePy)
does not directly provide user authentication, ssl or traffic compression
on his own.
Thus it's a worth idea to run behind a web server, specially if you want to
deploy it on a internet accessible computer.
You will get many other advantages as well:
- use the public URL you like, and let the web server map it to the program
internal URL
- run under SSL transparently
- use transparent authentication for the program
- compress traffic between MyNewspaper and the web browser
- integrate visits information with your site logs
With nginx
nginx is the web server I use nowdays, fast and powerful.
Example 1: use a virtual host: https://mynewspaper.domain.com
[...]
# enable and configure SSL and gzip compression
[...]
server {
listen 443;
server_name mynewspaper.domain.com;
ssl on;
access_log /var/log/nginx/mynewspaper-access.log main;
location / {
auth_basic "My Newspaper";
auth_basic_user_file "/etc/nginx/domain.com.users";
proxy_pass http://127.0.0.1:8887;
}
location /images {
disable_symlinks off;
alias /var/www/mynewspaper4/images;
}
location /static {
disable_symlinks off;
alias /var/www/mynewspaper4/static;
}
location /docs {
disable_symlinks off;
alias /var/www/mynewspaper4/docs;
}
}
[...]
With lighttpd
lighttpd is a fast, powerful web server with lot of features.
Example 1: use a virtual host: http://mynewspaper.domain.com
[...]
server.modules = ( ..., "mod_proxy", "mod_simple_vhost", ... )
[...]
$HTTP["host"] == "mynewspaper.domain.com" {
server.document-root = "/var/www/mynespaper/"
accesslog.filename = "/var/log/lighttpd/mynewspaper-access_log"
proxy.server = ( "" => (("host" => "127.0.0.1", "port" => 8887)) )
}
[...]
Example 2: rewrite url: http://www.domain.com/mynewspaper
[...]
server.modules = ( ..., "mod_rewrite", "mod_proxy", ... )
[...]
$HTTP["host"] == "www.domain.com" {
[...]
$HTTP["url"] =~ "^/mynewspaper" {
server.document-root = "/var/www/mynewspaper2"
url.rewrite-once = ( "^/mynewspaper(.*)$" => "/$1" )
proxy.server = ( "" => (("host" => "127.0.0.1", "port" => 8887)) )
}
[...]
}
[...]
With apache
apache, the most popular web server.
The concepts are quite similar to any other web server.
Other
There are other alternatives: FCGI, WSGI, running as CGI, etc.
More ideas in BottlePy_ documentation.
- Copy tools/mynewspaper.cron file to /etc/cron.d with the name
mynewspaper
- Uncomment the proper line depending on how you want to access the application:
internal web or web front. By default, it will update feeds each 30 minutes
- Finally, restart cron daemon
# cp tools/mynewspaper.cron /etc/cron.d/mynewspaper
# [edit] /etc/cron.d/mynewspaper
# systemctl restart crond # or /etc/init.d/crond restart
If you don't understand anything, consult your cron documentation.
Of course, you can fetch new articles from the web UI too.
Nowdays I use supervisor to start, run and control my python web applications.
This is the configuration file I use, from /etc/supervisor.d/web_mynewspaper.ini:
[program:web_mynewspaper]
command=/home/www/mynewspaper4/mynewspaper.py
directory=/home/www/mynewspaper4
priority=100
autostart=true
autorestart=true
user=www
log_stdout=true
log_stderr=true
logfile=/var/log/supervisord/web_mynewspaper.log
logfile_maxbytes=1MB
logfile_backups=5
Anyway you could easily create your own systemctl or init.d scripts.