1

Ubuntuを使用してApache2サーバーにDjangoアプリをセットアップしようとしています。次のチュートリアルを使用して、基本的なことを行いました。
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04

次のソリューションも使用しましたが、うまくいきませんでした。
Apache 仮想ホストで共存する Django (wsgi) と Wordpress

その他の参考文献:
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/

apache2 の構成ファイルは次のとおりです。

<VirtualHost *:80>

    Alias /static /home/ubuntu/test_pfi_app/static
    #Alias /media /home/ubuntu/test_pfi_app/media

    #DocumentRoot /var/www/html

    <Directory /home/ubuntu/test_pfi_app/static>
        Require all granted
    </Directory>

    WSGIDaemonProcess myproject python-path=/home/ubuntu/test_pfi_app:/usr/local/lib/python2.7/site-packages
    WSGIProcessGroup myproject
    WSGIScriptAlias /django /home/ubuntu/test_pfi_app/myproject/wsgi.py process-group=myproject
    #WSGIScriptAliasMatch /django /home/ubuntu/test_pfi_app/myproject/wsgi.py

    <Directory /home/ubuntu/test_pfi_app/myproject>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
ServerName app1.example.co.in
DocumentRoot /var/www/html/ocdemo
</VirtualHost>

<VirtualHost *:80>
ServerName app2.example.co.in
DocumentRoot /var/www/html/echosuat
</VirtualHost>

<VirtualHost *:80>
ServerName task.example.co.in
DocumentRoot /var/www/html/tasks
</VirtualHost>

を使用してdjangoアプリにアクセスできますが、サーバーのルートにアクセスすると、下の画像に示すようにURLにIP/djangoリダイレクトされます。/var/www

ここに画像の説明を入力

そして、他のすべてのアプリは、からIP/html/app_nameアクセスできる必要がありますが、からアクセスできますIP/app_name

構成ファイルで正しい構成を行うことができません。

また、にアクセスしても「django へようこそ」ページが表示されませんIP/django。むしろ「ページが見つかりません(404)」 が表示されます

へのアクセス時に、デフォルトの django ページを取得できませんIP/django
ここに画像の説明を入力

アクセス時にこのページを取得しIP/django
ても、問題なくIP/django/admin動作します。
ここに画像の説明を入力

4

2 に答える 2

0

構成ドキュメントについて詳しく読んだ後、最終的に解決策にたどり着きました。

<VirtualHost *:80>

    Alias /static /home/ubuntu/app/static
    Alias /media /home/ubuntu/app/media

    DocumentRoot /var/www/html

    <Directory /home/ubuntu/app/static>
        Require all granted
    </Directory>

    WSGIDaemonProcess app python-path=/home/ubuntu/app:/usr/local/lib/python2.7/site-packages
    WSGIProcessGroup app
    WSGIScriptAlias /django /home/ubuntu/app/app/wsgi.py process-group=app

    <Directory /home/ubuntu/app/app>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
ServerName ocdemo.example.co.in
DocumentRoot /var/www/html/ocdemo
</VirtualHost>

<VirtualHost *:80>
ServerName echosuat.example.co.in
DocumentRoot /var/www/html/echosuat
</VirtualHost>

<VirtualHost *:80>
ServerName task.example.co.in
DocumentRoot /var/www/html/tasks
</VirtualHost>

変更する必要があったのは、django アプリの構成に DocumentRoot を追加することだけでした。

于 2015-12-27T09:55:57.770 に答える