NGINX Server Blocks

Bitnami NGINX WordPress 환경에서 Virtual Host 생성

Terminal 에서 app 폴더 생성

cd /opt/bitnami/
sudo mkdir apps
sudo chown bitnami.bitnami apps

yii2 폴더 생성

cd apps
mkdir yii2

yii2 설치

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii2
cd yii2


Nginx 설정 파일(1) 생성

cd /opt/bitnami/apps/ 
mkdir conf 
cd conf 
nano nginx-app.conf


index index.php index.html index.htm;

if ($request_uri !~ "^/phpmyadmin.*$")
  set $test  A;
if ($request_uri !~ "^/bitnami.*$")
  set $test  "${test}B";
if (!-e $request_filename)
  set $test  "${test}C";
if ($test = ABC) {
  rewrite ^/(.+)$ /index.php?q=$1 last;

# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
  deny all;

# Disable logging for not found files and access log for the favicon and robots

# Deny all attempts to access hidden files such as .htaccess or .htpasswd.
location ~ /\. {
    deny all;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_read_timeout 300;
    fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include fastcgi_params;

Nginx 설정 파일(2) 생성

nano yii2-prefix.conf


location /yii2 {
alias "/opt/bitnami/apps/yii2/frontend/web";
include "/opt/bitnami/apps/conf/nginx-app.conf";

Nginx Vhosts 설정 파일 생성

nano yii2-vhosts.conf


server {

    listen    80;
    root   "/opt/bitnami/apps/yii2/frontend/web";
    include "/opt/bitnami/apps/conf/nginx-app.conf";

server {

    listen    443 ssl http2;
    root   "/opt/bitnami/apps/yii2/frontend/web";

       ssl_certificate      /opt/bitnami/nginx/conf/bitnami/certs/server.crt;
       ssl_certificate_key  /opt/bitnami/nginx/conf/bitnami/certs/server.key;

       ssl_session_cache    shared:SSL:1m;
       ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
#change this folder name
    include "/opt/bitnami/apps/conf/nginx-app.conf";

Nginx Vhosts 기본 설정 파일 수정

cd /opt/bitnami/nginx/conf/server_blocks
nano wordpress-https-server-block.conf

Add this Inside of server {} block

include "/opt/bitnami/apps/conf/*-prefix.conf";

Add this outside of server {} block

include "/opt/bitnami/apps/conf/*-vhosts.conf";

Test NGINX server configuration

sudo nginx -t

Document Folder 권한 수정(wordpress 일 경우)

sudo chown bitnami:daemon -R /opt/bitnami/apps/yii2/*
sudo chmod -R g+w /opt/bitnami/apps/yii2*

NGINX 서버 재시작

 sudo /opt/bitnami/ restart nginx