LoginSignup
0
1

More than 3 years have passed since last update.

AWS Lightsail(BITNAME) でVirtualhostを作成しサブドメインでNginxで公開

Posted at

はじめに

AWS Lightsailで初めてBITNAMEを使用した。
クセはないが設定ファイルの場所やsocketファイルの配置先が一般的ものとは違う、気を付けよう。

設定方法

Virtualhostにwww.sample.comというサブドメインを紐づけます。
DNSだったりCDNだったりの設定は適宜よろしくです。

ディレクトリ作成

雑にディレクトリを作成。

mkdir -p /opt/bitnami/nginx/html/www.sample.com

Nginxの設定ファイルを変更

以下がサンプル。
設定ファイルは/etc配下にないので注意。
ここから~ここまでを参考にしてください。

/opt/bitnami/nginx/conf/nginx.conf
# Based on https://www.nginx.com/resources/wiki/start/topics/examples/full/#nginx-conf
user               daemon daemon;

worker_processes  auto;
error_log         "/opt/bitnami/nginx/logs/error.log";
pid               "/opt/bitnami/nginx/tmp/nginx.pid";

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format    main '$remote_addr - $remote_user [$time_local] '
                       '"$request" $status  $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
    access_log    "/opt/bitnami/nginx/logs/access.log";
    add_header    X-Frame-Options SAMEORIGIN;

    client_body_temp_path  "/opt/bitnami/nginx/tmp/client_body" 1 2;
    proxy_temp_path        "/opt/bitnami/nginx/tmp/proxy" 1 2;
    fastcgi_temp_path      "/opt/bitnami/nginx/tmp/fastcgi" 1 2;
    scgi_temp_path         "/opt/bitnami/nginx/tmp/scgi" 1 2;
    uwsgi_temp_path        "/opt/bitnami/nginx/tmp/uwsgi" 1 2;

    sendfile           on;
    tcp_nopush         on;
    tcp_nodelay        off;
    gzip               on;
    gzip_http_version  1.0;
    gzip_comp_level    2;
    gzip_proxied       any;
    gzip_types         text/plain text/css application/javascript text/xml application/xml+rss;
    keepalive_timeout  65;
    ssl_protocols      TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers        HIGH:!aNULL:!MD5;
    client_max_body_size 80M;
    server_tokens off;

    include  "/opt/bitnami/nginx/conf/server_blocks/*.conf";

    # HTTP Server
    server {
        # Port to listen on, can also be set in IP:PORT format
        listen  80;

        include  "/opt/bitnami/nginx/conf/bitnami/*.conf";

        location /status {
            stub_status on;
            access_log   off;
            allow 127.0.0.1;
            deny all;
        }
    }
    ## ここから ##
    server {
        listen 80;
        server_name www.sample.com;
        root /opt/bitnami/nginx/html/www.sample.com;

        location / {
            index index.html index.php;
        }


        location ~ \.php$ {
            fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    ## ここまで ##
}

再起動

sudo /opt/bitnami/ctlscript.sh restart

その他ハマり?ポイント

php-fmp関連

phpを使うために必要なphp-fmp君。
- 設定ファイルは/opt/bitnami/php/etc/php-fpm.d/www.confにある。
- socketファイルは/opt/bitnami/php/var/run/www.sock

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1