【3】NGINXの設定
/etc/nginx/sites-available/defaultに次の内容を追加します。
# for Django server { listen 80 ; # listen [::]:80 default_server ipv6only=on; # root /usr/share/nginx/html; # root /var/www/mysite/polls; # root /var/www/mysite; # index index.html index.htm; # Make site accessible from http://localhost/ server_name www.vote.com; # server_name localhost; access_log /var/log/nginx/vote_access.log; error_log /var/log/nginx/vote_error.log; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. # try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules uwsgi_pass 127.0.0.1:3031; include uwsgi_params; } # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests #location /RequestDenied { # proxy_pass http://127.0.0.1:8080; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # #error_page 500 502 503 504 /50x.html; #location = /50x.html { # root /usr/share/nginx/html; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
あえて、コメントは残しておきました。実際はdefaultのシンボリックリンクを/etc/nginx/sites-enabale/に作成する必要があります。このあたりは、ApacheのVirtual Hostの設定に似ていますね。/etc/nginx/nginx.confがメインの設定ファイルですが、この設定ファイルは最後の行で、/etc/nginx/sites-enable/defaultをインクルードしています。
そうしておいて、sudo service nginx restartとなります。
【4】uWSGIの設定
/etc/uwsgi/apps-availableに次のようなmysite.iniを作成して、そのシンボリックファイルをapps-enableに作ります。apps-enableに実体を作成すりゃいいじゃないかとも思いますが、Apache以来の伝統ですね。(^_^;)。
[uwsgi] plugins = python3 chdir = /var/www/mysite/ socket = 127.0.0.1:3031 master = True vacuum = True DEBUG = True module = mysite.wsgi:application daemonize = /var/log/uwsgi/mysite.log
一番上の行は要らないかも知れません。また、ポート番号は必ずしも3031である必要はないようです。ただし、nginxのdefaultのポート設定と合わせる必要はあります。
とこうしておいて、sudo service uwsgi restartとやります。その後、/etc/hostsにwww.vote.com 192.168.1.2を追加して、http://www.vote.comとやれば、次のトップ画面になります。
この画面で、管理画面へログインをクリックすると、IDとPasswordの入力画面になります。
ログインすれば、冒頭のバックエンドに入り、質問内容と回答(複数)を入力することができます。もちろん、日本語も通ります。
【5】その他
必ずしも、/var/wwwにDjangoのプロジェクトを作る必要はないのですが、/var/wwwをメインのドキュメントルートにしましたので、そうしました。次に、NginxでCakePHP2を動かすための設定を紹介する予定ですが、/var/www以下のディレクトリ、ファイルの所有者はユーザー、グループはwww-data(Debian/Ubuntu系では、ブラウザからHTTPサーバーのApacheならびにNginxにアクセスするユーザーはwww-dataです。RedHat/CentOS系はapache)。それで、ディレクトのパーミッションは775、ファイルのパーミッションは664にする必要がありますが、まとめて変更するスクリプトを作成してみました。
#!/usr/bin/env python # -*- coding: utf-8 -*- import os def changepermission(dirname): for filename in os.listdir(dirname): # print(filename + 'が存在します。') fullpathname = dirname + '/' + filename # print (fullpathname) if os.path.isdir(fullpathname)==True: # print(filename + 'はディレクトリです') try: os.chmod(fullpathname, 0o775) # os.chmod(fullpathname, 0775) in Python2.x changepermission(fullpathname) except: print(filename + "の属性は変更できませんでした。") elif os.path.isfile(fullpathname)==True: # print(filename + 'はファイルです。') try: os.chmod(fullpathname, 0o664) # os.chmod(fullpathname, 0664) in Python2.x except: print(fullpathname + "の属性は変更できませんでした。") if __name__ == '__main__': print("Waiting a fiew minutes...") changepermission('/var/www') print("Done !!")
シェルコマンドないしスクリプトなら、一発かも知れませんが、Pythonもいいですね。