質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Q&A

0回答

2542閲覧

Apache2.4:Ubuntu上で複数のDjangoプロジェクトを動かしたい

Ykkykk

総合スコア140

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

0グッド

0クリップ

投稿2019/02/13 03:53

編集2019/02/14 08:14

UbuntuにDjangoとApache2.4をインストールし、サイトを動かそうとしています。

Djangoでexample1とexample2という別のプロジェクトを作成し、それぞれを一つのApache上で動かしたいのですが、片方ずつしか動かせない状態です。

/etc/apache2/sites-available/django.conf

以上の場所にdjango.confというファイルを作成し、Apacheの設定を行いました。

django.conf

1<VirtualHost *:80> 2ServerName example1 3WSGIDaemonProcess project1 python-home=/usr python-path=/home/path/to/directory 4WSGIProcessGroup project1 5WSGIScriptAlias / /home/path/to/wsgi.py process-group=project1 6<Directory /home/path/to/directory> 7 <Files wsgi.py> 8 Require all granted 9 </Files> 10</Directory> 11 12Alias /static/ /home/path/to/static/ 13<Directory /home/path/to/static> 14 Require all granted 15</Directory> 16</VirtualHost> 17 18<VirtualHost *:80> 19ServerName example2 20WSGIDaemonProcess project2 python-home=/usr python-path=/home/path/to/directory 21WSGIProcessGroup project2 22WSGIScriptAlias / /home/path/to/wsgi.py process-group=project2 23<Directory /home/path/to/directory> 24 <Files wsgi.py> 25 Require all granted 26 </Files> 27</Directory> 28 29Alias /static/ /home/path/to/static/ 30<Directory /home/path/to/static> 31 Require all granted 32</Directory> 33</VirtualHost>

パスはそれぞれのプロジェクトの正しいパスを書いています。
しかし、上記の設定でサイトにアクセスすると、example1は表示されるのですが、example2はDjangoのPageNotFoundエラーの画面が返ってきます。
エラー内容を確認すると、example1のurls.pyを見ているようで、example2が認識されていません。

django.confファイルを、django1.confファイルとdjango2.confファイルに分割し、それぞれをa2ensiteで有効化してみたのですが、そうしたところ、exmaple2は表示される一方で、exmaple1はDjangoのPageNotFoundエラーの画面が表示されました。エラー内容も、先ほどまでのエラー内容と同じでした。

どのように設定すれば、両方とも動かすことができるのでしょうか?
ご教示いただけますと幸いです。よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Ykkykk

2019/02/14 00:30

お教えいただきありがとうございます。 一応すでにwsgi.pyもお知らせ頂いたように修正してあり、またデーモンモードも使用しているのですが、うまくいっていない状態です。 ありがとうございます。
wwbQzhMkhhgEmhU

2019/02/14 03:06

そうですかー。まぁダメ元情報だったので、仕方ないですね。 あと今見て気づいたのですが、2つ目のWSGIScriptAliasでprocess-group=project1って書いてありますが、これproject2でないと意図が違ってしまう気がするのですが、誤植です?
Ykkykk

2019/02/14 08:15

ご質問ありがとうございます。 コードでは正しく書いていたのですが、質問のコードでは打ち間違っていました。。。 修正いたしました。
wwbQzhMkhhgEmhU

2019/02/14 13:06

ちょっと内容が分からないことには分からないですね。 ディレクトリとエラーの両方が隠れているので推測ができないです。 とりあえず自分の環境では何となく動作しました。 デバッグ設定のvirtualenv環境をそのままapacheのvirtualhostで動作させただけなので、プロジェクトはルートになってないですし、両方のホスト名でadmin含む全プロジェクト見えちゃいましたが。。。
Ykkykk

2019/02/15 00:39

何度もありがとうございます。 初歩的なことで申し訳ないのですが、「プロジェクトはルートになっていない」ということはどういうことなのでしょうか? 質問で記載した設定だとどの部分がおっしゃっている箇所になるのでしょうか? python-pathやWSGIScriptAliasの部分でしょうか…?
wwbQzhMkhhgEmhU

2019/02/15 01:10

はい、その辺です。面倒なので貼っちゃいますね。 <VirtualHost *:80> ServerName lubuntu WSGIDaemonProcess testapp1 home=/home/user/python/testdjango3 python-home=/home/user/.virtualenvs/testdjango3 python-path=/home/user/.virtualenvs/testdjango3/bin/python user=user WSGIProcessGroup testapp1 WSGIScriptAlias / /home/user/python/testdjango3/testsite/wsgi.py process-group=testapp1 <Directory /home/user/python/testdjango3/testsite> <Files wsgi.py> Require all granted </Files> </Directory> Alias /static/ /home/user/python/testdjango3/testsite/static/ <Directory /home/user/python/testdjango3/testsite> Require all granted </Directory> </VirtualHost> <VirtualHost *:80> ServerName lubuntu2 WSGIDaemonProcess testapp2 home=/home/user/python/testdjango3 python-home=/home/user/.virtualenvs/testdjango3 python-path=/home/user/.virtualenvs/testdjango3/bin/python user=user WSGIProcessGroup testapp2 WSGIScriptAlias / /home/user/python/testdjango3/testsite/wsgi.py process-group=testapp2 <Directory /home/user/python/testdjango3/testsite> <Files wsgi.py> Require all granted </Files> </Directory> Alias /static/ /home/user/python/testdjango3/static/ <Directory /home/user/python/testdjango3/static> Require all granted </Directory> </VirtualHost>
wwbQzhMkhhgEmhU

2019/02/15 01:12

プロジェクトというよりアプリと言った方が適切でしたね。 そういやプロジェクト自体は共通なのだと思っていたのですが、別プロジェクトなのです?
wwbQzhMkhhgEmhU

2019/02/15 01:13

あ、プロジェクトは別と書いていましたね 別にしてみます
wwbQzhMkhhgEmhU

2019/02/15 01:32

別にしてみました。動いているようです。 <VirtualHost *:80> ServerName lubuntu WSGIDaemonProcess testapp1 home=/home/user/python/testdjango2 python-home=/home/user/.virtualenvs/testdjango3 python-path=/home/user/.virtualenvs/testdjango3/bin/python user=user WSGIProcessGroup testapp1 WSGIScriptAlias / /home/user/python/testdjango2/testsite/wsgi.py process-group=testapp1 <Directory /home/user/python/testdjango2/testsite> <Files wsgi.py> Require all granted </Files> </Directory> Alias /static/ /home/user/python/testdjango2/testsite/static/ <Directory /home/user/python/testdjango2/testsite> Require all granted </Directory> </VirtualHost> <VirtualHost *:80> ServerName lubuntu2 WSGIDaemonProcess testapp2 home=/home/user/python/testdjango3 python-home=/home/user/.virtualenvs/testdjango3 python-path=/home/user/.virtualenvs/testdjango3/bin/python user=user WSGIProcessGroup testapp2 WSGIScriptAlias / /home/user/python/testdjango3/testsite/wsgi.py process-group=testapp2 <Directory /home/user/python/testdjango3/testsite> <Files wsgi.py> Require all granted </Files> </Directory> Alias /static/ /home/user/python/testdjango3/testsite/static/ <Directory /home/path/to/static> Require all granted </Directory> </VirtualHost>
wwbQzhMkhhgEmhU

2019/02/15 01:34

virtualenvは元々別だったのですが、wsgiのインストールに時間がかかるので、apacheからは同じのを使わせてます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問