I'm very new to deployment. I'm trying to deploy two Mezzanine 4.2.3 projects (they use Django 1.10.8 according to requirements.txt) on Ubuntu 16.04. I deployed the first one successfully with this tutorial. I can access it via its domain name, say, example.com
. I'm trying to get the other one accessible on either food.example.com
or preferably example.com/food
but the browser returns: "server IP address could not be found".
The nginx config for example.com
at /etc/nginx/sites-available/example
:
server {
listen 80;
server_name [SERVER IP ADDRESS] example.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/example;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/example/example.sock;
}
The nginx config for food.example.com
at /etc/nginx/sites-available/food
:
server {
listen 81;
server_name food.example.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/food;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/food/food.sock;
}
}
I tried to use example.com/food
but nginx kept saying there're suspicious symbols in it. I don't know if that's one of the problems preventing the page from being displayed but I changed it to the subdomain food
anyway to try and isolate the issue.
The gunicorn config file for example.com
at /etc/systemd/system/gunicorn_example.service
:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/example
ExecStart=/home/example/env_example/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/example/example.sock example.wsgi:application
[Install]
WantedBy=multi-user.target
The gunicorn config file for food.example.com
at /etc/systemd/system/gunicorn_food.service
:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/food
ExecStart=/home/food/env_food/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/food/food.sock food.wsgi:application
[Install]
WantedBy=multi-user.target
Nginx log shows no errors.
systemctl status
for nginx, gunicorn_example
, and gunicorn_food
seem to indicate everything's fine. nginx -t
says nginx.conf
syntax and test are ok.
Both gunicorn_example
and gunicorn_food.service
are running.
Both example.sock
and food.sock
were successfully generated.
ps aux | grep gunicorn
shows workers running.
Not sure if this is an important detail but I don't use supervisor or upstart for deployment.
I'm guessing I've written the urls wrong. But I've tried various combinations and haven't gotten it right.
example.com
's urls.pyin the same folder as
settings.py`:
urlpatterns += [
url("^$", views.blog_post_list_index, name="home"),
]
food.example.com
's urls.py
in the same folder as settings.py
:
urlpatterns += [
url("^food.example.com$", views.blog_post_list_index, name="home"),
url("^food.example.com/", include('food_crud.urls')),
url("^", include("mezzanine.urls")),
]
The app's urls.py
in the app directory:
urlpatterns += [
url('add/$', food_crud_views.FoodCreateView.as_view(), name='food add'),
url('list/$', food_crud_views.FoodListView.as_view(), name='food list'),
url('(?P<pk>\d+)/$', food_crud_views.FoodDetailView.as_view(), name='food detail'),
url('(?P<pk>\d+)/update$', food_crud_views.FoodUpdateView.as_view(), name='food update'),
url('(?P<pk>\d+)/delete$', food_crud_views.FoodDeleteView.as_view(), name='food delete'),
]
What have I missed?
Edit 18 Feb 2018: ALLOWED_HOSTS
in settings.py
contains only ["example.com/food,"]
.
After reading up more, asking on IRC, and experimenting some more, it turns out the only thing I had to do was to make both projects listen on port 80.
This puzzles me because most articles I read say to have them listen on different ports. Going to have to investigate more in this direction.