「実践Rustプログラミング入門」に入門する(9日目)Section5-1Webフレームワークのセットアップpp.190


Ubuntu18.04上でApache2のリバースプロキシを設定し、actix-webのアプリケーションを動かす。

# Vagrantfile

```ruby:Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"

  # apache2
  config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  # actix-web
  config.vm.network "forwarded_port", guest: 8090, host: 8090, host_ip: "127.0.0.1"
  
  config.vm.network "private_network", ip: "192.168.33.10"

  # config.vm.network "public_network"

  config.vm.synced_folder "./data", "/vagrant_data"

  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
    vb.memory = "2048"
  end

  config.vm.provision "shell", inline: <<-SHELL
    apt-get update

    # To solve the issue of "vagrant@127.0.0.1: permission denied (publickey)."
    sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config; \
    sudo systemctl restart sshd;

    apt install -y apache2
    # cargo install cargo-editの中で使うパッケージをインストールする。
    apt install -y gcc libssl-dev
  SHELL
end

```

# `cargo install cargo-edit`でハマる
Windowsだと一撃で完了したのだが、Ubuntu上ではいろいろとインストール、設定をしないといけない。

`rustup`をインストールする。途中の選択肢はDefault(1)で良い。

```shell
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

`rustup`をインストールした時点で、`~/.profile`には`cargo`を動かすための`PATH`設定が行われている。追加されただけなので、`source ~/.profile`するか、再度ログインしないと有効にはならない。

```bash:~/.profile
export PATH="$HOME/.cargo/bin:$PATH"
```

## cargo-editのインストール
ここはハマった。Ubuntuが`cargo-edit`の想定とは違うところにopensslのライブラリをインストールしているのが原因。

以下のパッケージは、`cargo-edit`をインストールするために必要なのでインストールする(Vagrantfileに記載してある)

```shell
$ sudo apt install -y gcc libssl-dev
```

どこにどのようなファイルがインストールされたか確認しておく。

```shell
$ dpkg -L libssl-dev
/.
/usr
/usr/include
/usr/include/openssl
/usr/include/openssl/aes.h
/usr/include/openssl/asn1.h
/usr/include/openssl/asn1_mac.h
/usr/include/openssl/asn1err.h
/usr/include/openssl/asn1t.h
/usr/include/openssl/async.h
/usr/include/openssl/asyncerr.h
/usr/include/openssl/bio.h
/usr/include/openssl/bioerr.h
/usr/include/openssl/blowfish.h
/usr/include/openssl/bn.h
/usr/include/openssl/bnerr.h
/usr/include/openssl/buffer.h
/usr/include/openssl/buffererr.h
/usr/include/openssl/camellia.h
/usr/include/openssl/cast.h
/usr/include/openssl/cmac.h
/usr/include/openssl/cms.h
/usr/include/openssl/cmserr.h
/usr/include/openssl/comp.h
/usr/include/openssl/comperr.h
/usr/include/openssl/conf.h
/usr/include/openssl/conf_api.h
/usr/include/openssl/conferr.h
/usr/include/openssl/crypto.h
/usr/include/openssl/cryptoerr.h
/usr/include/openssl/ct.h
/usr/include/openssl/cterr.h
/usr/include/openssl/des.h
/usr/include/openssl/dh.h
/usr/include/openssl/dherr.h
/usr/include/openssl/dsa.h
/usr/include/openssl/dsaerr.h
/usr/include/openssl/dtls1.h
/usr/include/openssl/e_os2.h
/usr/include/openssl/ebcdic.h
/usr/include/openssl/ec.h
/usr/include/openssl/ecdh.h
/usr/include/openssl/ecdsa.h
/usr/include/openssl/ecerr.h
/usr/include/openssl/engine.h
/usr/include/openssl/engineerr.h
/usr/include/openssl/err.h
/usr/include/openssl/evp.h
/usr/include/openssl/evperr.h
/usr/include/openssl/hmac.h
/usr/include/openssl/idea.h
/usr/include/openssl/kdf.h
/usr/include/openssl/kdferr.h
/usr/include/openssl/lhash.h
/usr/include/openssl/md2.h
/usr/include/openssl/md4.h
/usr/include/openssl/md5.h
/usr/include/openssl/mdc2.h
/usr/include/openssl/modes.h
/usr/include/openssl/obj_mac.h
/usr/include/openssl/objects.h
/usr/include/openssl/objectserr.h
/usr/include/openssl/ocsp.h
/usr/include/openssl/ocsperr.h
/usr/include/openssl/opensslv.h
/usr/include/openssl/ossl_typ.h
/usr/include/openssl/pem.h
/usr/include/openssl/pem2.h
/usr/include/openssl/pemerr.h
/usr/include/openssl/pkcs12.h
/usr/include/openssl/pkcs12err.h
/usr/include/openssl/pkcs7.h
/usr/include/openssl/pkcs7err.h
/usr/include/openssl/rand.h
/usr/include/openssl/rand_drbg.h
/usr/include/openssl/randerr.h
/usr/include/openssl/rc2.h
/usr/include/openssl/rc4.h
/usr/include/openssl/rc5.h
/usr/include/openssl/ripemd.h
/usr/include/openssl/rsa.h
/usr/include/openssl/rsaerr.h
/usr/include/openssl/safestack.h
/usr/include/openssl/seed.h
/usr/include/openssl/sha.h
/usr/include/openssl/srp.h
/usr/include/openssl/srtp.h
/usr/include/openssl/ssl.h
/usr/include/openssl/ssl2.h
/usr/include/openssl/ssl3.h
/usr/include/openssl/sslerr.h
/usr/include/openssl/stack.h
/usr/include/openssl/store.h
/usr/include/openssl/storeerr.h
/usr/include/openssl/symhacks.h
/usr/include/openssl/tls1.h
/usr/include/openssl/ts.h
/usr/include/openssl/tserr.h
/usr/include/openssl/txt_db.h
/usr/include/openssl/ui.h
/usr/include/openssl/uierr.h
/usr/include/openssl/whrlpool.h
/usr/include/openssl/x509.h
/usr/include/openssl/x509_vfy.h
/usr/include/openssl/x509err.h
/usr/include/openssl/x509v3.h
/usr/include/openssl/x509v3err.h
/usr/include/x86_64-linux-gnu
/usr/include/x86_64-linux-gnu/openssl
/usr/include/x86_64-linux-gnu/openssl/opensslconf.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libcrypto.a
/usr/lib/x86_64-linux-gnu/libssl.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libcrypto.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/libssl.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc
/usr/share
/usr/share/doc
/usr/share/doc/libssl-dev
/usr/lib/x86_64-linux-gnu/libcrypto.so
/usr/lib/x86_64-linux-gnu/libssl.so
/usr/share/doc/libssl-dev/changelog.Debian.gz
/usr/share/doc/libssl-dev/changelog.gz
/usr/share/doc/libssl-dev/copyright
```

'cargo-edit'は、`OPENSSL_DIR`環境変数で指定されたディレクトリの下の`lib`及び`include`ディレクトリを使用するので、リンクを張る。

```shell
sudo ln -sf /usr/lib/x86_64-linux-gnu/ /usr/lib/ssl/lib
sudo ln -sf /usr/include/openssl /usr/lib/ssl/include
```

さらに、`~/.profile`に`OPENSSL_DIR`を設定する。

```bash:~/.profile
export OPENSSL_DIR="/usr/lib/ssl"
```

`.profile`を読み込みなおした上、環境変数の設定を確認する。

```shell
$ source ~/.profile
$ env | grep OPENSSL_DIR
OPENSSL_DIR=/usr/lib/ssl
```

`cargo-edit`をインストールする。手元のマシンではほぼ13分かかった。

```shell
$ cargo install cargo-edit
    Updating crates.io index
  Installing cargo-edit v0.6.0
   Compiling libc v0.2.76
   Compiling autocfg v1.0.1
   Compiling cfg-if v0.1.10
   Compiling pkg-config v0.3.18
   Compiling proc-macro2 v1.0.20
   Compiling unicode-xid v0.2.1
   Compiling version_check v0.9.2
   Compiling syn v1.0.40
   Compiling log v0.4.11
   Compiling memchr v2.3.3
   Compiling lazy_static v1.4.0
   Compiling bitflags v1.2.1
   Compiling itoa v0.4.6
   Compiling bytes v0.5.6
   Compiling fnv v1.0.7
   Compiling slab v0.4.2
   Compiling futures-core v0.3.5
   Compiling serde v1.0.115
   Compiling pin-project-internal v0.4.23
   Compiling pin-project-lite v0.1.7
   Compiling matches v0.1.8
   Compiling tinyvec v0.3.4
   Compiling foreign-types-shared v0.1.1
   Compiling openssl v0.10.30
   Compiling once_cell v1.4.1
   Compiling futures-sink v0.3.5
   Compiling futures-io v0.3.5
   Compiling percent-encoding v2.1.0
   Compiling pin-utils v0.1.0
   Compiling openssl-probe v0.1.2
   Compiling httparse v1.3.4
   Compiling hashbrown v0.9.0
   Compiling native-tls v0.2.4
   Compiling byteorder v1.3.4
   Compiling ryu v1.0.5
   Compiling try-lock v0.2.3
   Compiling gimli v0.22.0
   Compiling adler v0.2.3
   Compiling rustc-demangle v0.1.16
   Compiling serde_derive v1.0.115
   Compiling unicode-width v0.1.8
   Compiling tower-service v0.3.0
   Compiling failure_derive v0.1.8
   Compiling void v1.0.2
   Compiling unicode-segmentation v1.6.0
   Compiling object v0.20.0
   Compiling serde_json v1.0.57
   Compiling encoding_rs v0.8.24
   Compiling strsim v0.8.0
   Compiling dtoa v0.4.6
   Compiling either v1.6.0
   Compiling vec_map v0.8.2
   Compiling ansi_term v0.11.0
   Compiling semver-parser v0.7.0
   Compiling mime v0.3.16
   Compiling ascii v0.9.3
   Compiling base64 v0.12.3
   Compiling regex-syntax v0.6.18
   Compiling linked-hash-map v0.5.3
   Compiling ipnet v2.3.0
   Compiling termcolor v1.1.0
   Compiling hex v0.4.2
   Compiling indexmap v1.6.0
   Compiling num-traits v0.2.12
   Compiling num-integer v0.1.43
   Compiling unicase v2.6.0
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling error-chain v0.12.4
   Compiling tracing-core v0.1.16
   Compiling thread_local v1.0.1
   Compiling http v0.2.1
   Compiling futures-channel v0.3.5
   Compiling unicode-bidi v0.3.4
   Compiling unicode-normalization v0.1.13
   Compiling foreign-types v0.3.2
   Compiling futures-task v0.3.5
   Compiling miniz_oxide v0.4.1
   Compiling textwrap v0.11.0
   Compiling unreachable v1.0.0
   Compiling addr2line v0.13.0
   Compiling heck v0.3.1
   Compiling http-body v0.3.1
   Compiling idna v0.2.0
   Compiling quote v1.0.7
   Compiling jobserver v0.1.21
   Compiling net2 v0.2.35
   Compiling iovec v0.1.4
   Compiling num_cpus v1.13.0
   Compiling time v0.1.44
   Compiling socket2 v0.3.12
   Compiling backtrace v0.3.50
   Compiling atty v0.2.14
   Compiling dirs-sys v0.3.5
   Compiling subprocess v0.2.4
   Compiling tracing v0.1.19
   Compiling want v0.3.0
   Compiling aho-corasick v0.7.13
   Compiling url v2.1.1
   Compiling semver v0.9.0
   Compiling toml v0.5.6
   Compiling combine v3.8.1
   Compiling cc v1.0.59
   Compiling mio v0.6.22
   Compiling clap v2.33.3
   Compiling dirs v2.0.2
   Compiling mime_guess v2.0.3
   Compiling regex v1.3.9
   Compiling serde_urlencoded v0.6.1
   Compiling env_proxy v0.4.1
   Compiling chrono v0.4.15
   Compiling synstructure v0.12.4
   Compiling openssl-sys v0.9.58
   Compiling libz-sys v1.1.2
   Compiling libssh2-sys v0.2.19
   Compiling libgit2-sys v0.12.13+1.0.1
   Compiling tokio v0.2.22
   Compiling toml_edit v0.1.5
   Compiling structopt-derive v0.4.10
   Compiling tokio-util v0.3.1
   Compiling pin-project v0.4.23
   Compiling cargo_metadata v0.9.1
   Compiling structopt v0.3.17
   Compiling failure v0.1.8
   Compiling futures-util v0.3.5
   Compiling h2 v0.2.6
   Compiling hyper v0.13.7
   Compiling tokio-tls v0.3.1
   Compiling hyper-tls v0.4.3
   Compiling reqwest v0.10.8
   Compiling git2 v0.13.11
   Compiling cargo-edit v0.6.0
    Finished release [optimized] target(s) in 12m 59s
  Installing /home/vagrant/.cargo/bin/cargo-add
  Installing /home/vagrant/.cargo/bin/cargo-rm
  Installing /home/vagrant/.cargo/bin/cargo-upgrade
   Installed package `cargo-edit v0.6.0` (executables `cargo-add`, `cargo-rm`, `cargo-upgrade`)
```

p.190を参考に、`actix-web`を有効にする。

```shell
$ cargo add actix-web actix-rt
    Updating 'https://github.com/rust-lang/crates.io-index' index
      Adding actix-web v2.0.0 to dependencies
      Adding actix-rt v1.1.1 to dependencies
```

# actix-webアプリケーション

ソースコードは動作検証用なので、これだけ。

```rust:src/main.rs
use actix_web::{get, App, HttpResponse, HttpServer};

#[get("/")]
async fn index() -> Result<HttpResponse, actix_web::Error> {
    let response_body = "Hello Rustaceans!";
    Ok(HttpResponse::Ok().body(response_body))
}

#[actix_rt::main]
async fn main() -> Result<(), actix_web::Error> {
    HttpServer::new(move || App::new().service(index))
        .bind("0.0.0.0:8090")?
        .run()
        .await?;
    Ok(())
}
```

実行確認する。

```shell
$ cargo run
    Updating crates.io index
  Downloaded actix-web-codegen v0.2.2
  Downloaded arc-swap v0.4.7
  Downloaded base64 v0.11.0
  Downloaded brotli2 v0.3.2
  Downloaded bytestring v0.1.5
  Downloaded awc v1.0.1
  Downloaded copyless v0.1.5
  Downloaded futures v0.3.5
  Downloaded futures-executor v0.3.5
  Downloaded futures-macro v0.3.5
  Downloaded fxhash v0.2.1
  Downloaded hostname v0.3.1
  Downloaded lock_api v0.4.1
  Downloaded actix-web v2.0.0
  Downloaded language-tags v0.2.2
  Downloaded crc32fast v1.2.0
  Downloaded instant v0.1.6
  Downloaded match_cfg v0.1.0
  Downloaded lru-cache v0.1.2
  Downloaded mio-uds v0.6.8
  Downloaded proc-macro-nested v0.1.6
  Downloaded proc-macro-hack v0.5.18
  Downloaded parking_lot v0.11.0
  Downloaded quick-error v1.2.3
  Downloaded parking_lot_core v0.8.0
  Downloaded rand_chacha v0.2.2
  Downloaded rand_core v0.5.1
  Downloaded resolv-conf v0.6.3
  Downloaded scopeguard v1.1.0
  Downloaded signal-hook-registry v1.2.1
  Downloaded smallvec v1.4.2
  Downloaded trust-dns-proto v0.18.0-alpha.2
  Downloaded tokio-util v0.2.0
  Downloaded trust-dns-resolver v0.18.0-alpha.2
  Downloaded actix-server v1.0.3
  Downloaded actix-router v0.2.4
  Downloaded actix-service v1.0.6
  Downloaded actix-testing v1.0.1
  Downloaded actix-rt v1.1.1
  Downloaded actix-macros v0.1.2
  Downloaded actix-connect v1.0.2
  Downloaded actix-codec v0.2.0
  Downloaded async-trait v0.1.40
  Downloaded getrandom v0.1.14
  Downloaded threadpool v1.8.1
  Downloaded sha1 v0.6.0
  Downloaded actix-tls v1.0.0
  Downloaded actix-utils v1.0.6
  Downloaded actix-threadpool v0.3.3
  Downloaded ppv-lite86 v0.2.9
  Downloaded enum-as-inner v0.3.3
  Downloaded derive_more v0.99.9
  Downloaded rand v0.7.3
  Downloaded flate2 v1.0.17
  Downloaded actix-http v1.0.1
  Downloaded brotli-sys v0.3.2
  Downloaded 56 crates (2.1 MB) in 2.46s
   Compiling libc v0.2.76
   Compiling proc-macro2 v1.0.20
   Compiling unicode-xid v0.2.1
   Compiling cfg-if v0.1.10
   Compiling syn v1.0.40
   Compiling memchr v2.3.3
   Compiling log v0.4.11
   Compiling futures-core v0.3.5
   Compiling slab v0.4.2
   Compiling lazy_static v1.4.0
   Compiling futures-sink v0.3.5
   Compiling bytes v0.5.6
   Compiling pin-project-internal v0.4.23
   Compiling proc-macro-nested v0.1.6
   Compiling proc-macro-hack v0.5.18
   Compiling once_cell v1.4.1
   Compiling arc-swap v0.4.7
   Compiling pin-project-lite v0.1.7
   Compiling futures-io v0.3.5
   Compiling pin-utils v0.1.0
   Compiling smallvec v1.4.2
   Compiling autocfg v1.0.1
   Compiling instant v0.1.6
   Compiling scopeguard v1.1.0
   Compiling getrandom v0.1.14
   Compiling bitflags v1.2.1
   Compiling matches v0.1.8
   Compiling adler v0.2.3
   Compiling tinyvec v0.3.4
   Compiling failure_derive v0.1.8
   Compiling gimli v0.22.0
   Compiling itoa v0.4.6
   Compiling serde_derive v1.0.115
   Compiling copyless v0.1.5
   Compiling rustc-demangle v0.1.16
   Compiling object v0.20.0
   Compiling percent-encoding v2.1.0
   Compiling unicode-segmentation v1.6.0
   Compiling either v1.6.0
   Compiling ppv-lite86 v0.2.9
   Compiling serde v1.0.115
   Compiling match_cfg v0.1.0
   Compiling fnv v1.0.7
   Compiling cc v1.0.59
   Compiling ryu v1.0.5
   Compiling quick-error v1.2.3
   Compiling linked-hash-map v0.5.3
   Compiling byteorder v1.3.4
   Compiling crc32fast v1.2.0
   Compiling serde_json v1.0.57
   Compiling encoding_rs v0.8.24
   Compiling httparse v1.3.4
   Compiling regex-syntax v0.6.18
   Compiling hashbrown v0.9.0
   Compiling dtoa v0.4.6
   Compiling sha1 v0.6.0
   Compiling mime v0.3.16
   Compiling base64 v0.11.0
   Compiling language-tags v0.2.2
   Compiling tracing-core v0.1.16
   Compiling thread_local v1.0.1
   Compiling futures-channel v0.3.5
   Compiling bytestring v0.1.5
   Compiling futures-task v0.3.5
   Compiling lock_api v0.4.1
   Compiling num-traits v0.2.12
   Compiling num-integer v0.1.43
   Compiling indexmap v1.6.0
   Compiling unicode-bidi v0.3.4
   Compiling miniz_oxide v0.4.1
   Compiling unicode-normalization v0.1.13
   Compiling addr2line v0.13.0
   Compiling heck v0.3.1
   Compiling http v0.2.1
   Compiling lru-cache v0.1.2
   Compiling brotli-sys v0.3.2
   Compiling idna v0.2.0
   Compiling net2 v0.2.35
   Compiling iovec v0.1.4
   Compiling signal-hook-registry v1.2.1
   Compiling parking_lot_core v0.8.0
   Compiling num_cpus v1.13.0
   Compiling socket2 v0.3.12
   Compiling backtrace v0.3.50
   Compiling hostname v0.3.1
   Compiling time v0.1.44
   Compiling quote v1.0.7
   Compiling aho-corasick v0.7.13
   Compiling tracing v0.1.19
   Compiling fxhash v0.2.1
   Compiling url v2.1.1
   Compiling flate2 v1.0.17
   Compiling mio v0.6.22
   Compiling threadpool v1.8.1
   Compiling parking_lot v0.11.0
   Compiling rand_core v0.5.1
   Compiling resolv-conf v0.6.3
   Compiling regex v1.3.9
   Compiling brotli2 v0.3.2
   Compiling mio-uds v0.6.8
   Compiling rand_chacha v0.2.2
   Compiling synstructure v0.12.4
   Compiling chrono v0.4.15
   Compiling tokio v0.2.22
   Compiling rand v0.7.3
   Compiling futures-macro v0.3.5
   Compiling derive_more v0.99.9
   Compiling actix-macros v0.1.2
   Compiling async-trait v0.1.40
   Compiling enum-as-inner v0.3.3
   Compiling actix-web-codegen v0.2.2
   Compiling tokio-util v0.2.0
   Compiling tokio-util v0.3.1
   Compiling pin-project v0.4.23
   Compiling actix-threadpool v0.3.3
   Compiling failure v0.1.8
   Compiling actix-codec v0.2.0
   Compiling futures-util v0.3.5
   Compiling futures-executor v0.3.5
   Compiling actix-service v1.0.6
   Compiling actix-rt v1.1.1
   Compiling h2 v0.2.6
   Compiling futures v0.3.5
   Compiling serde_urlencoded v0.6.1
   Compiling actix-router v0.2.4
   Compiling actix-utils v1.0.6
   Compiling trust-dns-proto v0.18.0-alpha.2
   Compiling actix-server v1.0.3
   Compiling actix-tls v1.0.0
   Compiling actix-testing v1.0.1
   Compiling trust-dns-resolver v0.18.0-alpha.2
   Compiling actix-connect v1.0.2
   Compiling actix-http v1.0.1
   Compiling awc v1.0.1
   Compiling actix-web v2.0.0
   Compiling actix_test v0.1.0 (/home/vagrant/actix_test)
    Finished dev [unoptimized + debuginfo] target(s) in 3m 52s
     Running `target/debug/actix_test`
```

actix-web側の直接動作確認。8090を直接叩く。

![20200909_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2059/d27f45c7-8a65-80c9-3c2b-e20236bd0455.png)


Apache2の動作確認。8080ポート。

![20200909_02.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2059/90c598fd-c576-296e-4e0d-262a4ad671d6.png)

# Apache2の設定

モジュールを有効にする。

```shell
$ sudo a2enmod
Your choices are: access_compat actions alias allowmethods asis auth_basic auth_digest auth_form authn_anon authn_core authn_dbd authn_dbm authn_file authn_socache authnz_fcgi authnz_ldap authz_core authz_dbd authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex buffer cache cache_disk cache_socache cern_meta cgi cgid charset_lite data dav dav_fs dav_lock dbd deflate dialup dir dump_io echo env expires ext_filter file_cache filter headers heartbeat heartmonitor http2 ident imagemap include info lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic lbmethod_heartbeat ldap log_debug log_forensic lua macro mime mime_magic mpm_event mpm_prefork mpm_worker negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_express proxy_fcgi proxy_fdpass proxy_ftp proxy_hcheck proxy_html proxy_http proxy_http2 proxy_scgi proxy_wstunnel ratelimit reflector remoteip reqtimeout request rewrite sed session session_cookie session_crypto session_dbd setenvif slotmem_plain slotmem_shm socache_dbm socache_memcache socache_shmcb speling ssl status substitute suexec unique_id userdir usertrack vhost_alias xml2enc
Which module(s) do you want to enable (wildcards ok)?
proxy
Enabling module proxy.
To activate the new configuration, you need to run:
  systemctl restart apache2

$ sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
  systemctl restart apache2
```

リバースプロキシの設定を行う。
フォワードはしないのでProxyRequestsはOff。

```apache2.conf
ProxyRequests Off
ProxyPass /actix http://localhost:8090/
ProxyPassReverse /actix http://localhost:8090/
```

Apache2を再起動する。

```shell
$ sudo service apache2 restart
```

# Apachd2からのactic-web動作

`http://localhost/main_app`とするとメインの画面が出て、
`http://localhost/actix`とするとactix-webのレスポンスが返ってくる。

メインアプリは`http://localhost:8080/main_app`。

![20200909_03.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2059/a72dee0d-f00b-ce77-8c6c-ed36fe5c10a0.png)

actix-web側に`http://localhost:8080/actix`でアクセスする。

![20200909_04.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2059/a35223e3-e469-831d-9318-f3890190f785.png)


# 振り返り
1. Apache2とactix-webの連携方法を真剣に探してしまった。リバースプロキシすればいいに決まってる。
2. あとは、cargo runではなくてserviceで制御できるようにする。
3. httpsにも挑戦せねば。

# 参考資料

1. [ProxyRequests](https://httpd.apache.org/docs/2.4/ja/mod/mod_proxy.html)
2. [Apache 2.4 で リバースプロキシの設定](https://qiita.com/okiyuki99/items/83c1fb07644cd232d91e)
3. [mod_proxy再入門 – ProxyPassとProxyPassReverse](https://dev.classmethod.jp/articles/introduction_mod_proxy/)
4. [Ubuntu で Apache2 のモジュールを有効にする](https://qiita.com/kotarella1110/items/501a5076ed79e23a98f8)
5. [actix-web HTTPS Support](https://docs.rs/actix-web/0.7.19/actix_web/server/index.html)