予想通り不合理 -FXと機械学習と-

FXの自動売買や機械学習、その他勉強したことをシェアします

Apacheの勉強 AWSのUbuntuサーバを使ってWebサービス構築①

kapiparaです。

 

AWSのUbuntu16.04サーバを使って機械学習を用いたサービスを構築します。

前回Apacheのインストールまで完了しました。

 

バックエンドのPythonは完成しているので、あとは、

  • 画像のアップロードページ作成
  • 画像アップロードを検知してpythonに渡すプログラム作成
  • 処理後画像を表示するページ作成

が終われば完成です。

 

 

画像のアップロードページ作成

まずは画像のアップロードページ表示をするための勉強をします。

そもそもApacheに接続した際にどのディレクトリにあるファイルが表示されているのかもわかっていないため、手探りで調べていきます!

 

まずはhttp://xxx.xxx.xxx.xxx(EC2のIP) にアクセスした際にどのページが表示されているかの調査。

いろいろと調べてみましたが、まずややこしいのが、Ubuntuの場合、httpd.confというファイルは存在せず、代わりにapache2.confがある。ということ。

また、apache2.confの中ではなく、/etc/apache2/sites-available/000-default.confにドキュメントルートが設定されているということ。

 

ファイルの中身は以下の通り。

--------------------

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

---------------------------------------

 

上記に従うと、/var/www/htmlを参照しているとのこと。

見に行くと、確かにindex.htmlがあった。

試しにindex.html ⇒ index.htmlbkに変更してアクセスしてみた。

 

f:id:kapipara18:20170717103341p:plain

ディレクトリ情報が返ってきました。成功です。

いろいろとやり口は考えられますが、普段使いしているディレクトリを参照したほうがいろいろ楽そうなので、設定内容の変更。

 

----------------

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /home/ubuntu/apache2/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

-------------------------

加えて、URLの最後の「/」がない場合に、ファイル検索をかけてくれるよう(のはず)apache2.confの内容も変更。

-------------------------

<Directory /home/ubuntu/apache2>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

---------------------------

 

所定のディレクトリにindexとphpを配置し、apache2の再起動もかます。

(index,phpは以下のサイト参照)

qiita.com

httpアクセス。でた!

f:id:kapipara18:20170717110406p:plain

一旦以上。