Laradock (2) : 設定


Posted by JingTeng on 2020-07-21

目標:
在 windows 開發環境上設定前端、後端各自的專案與前後端本地網址。

Step 1 – 建立專案
Step 2 – 設定 nginx/.env
Step 3 – 設定 nginx/sites/[projectName].conf
Step 4 – 改 /ect/hosts
Step 5 – 運行 laradock 和瀏覽器
step 6 - 連結資料庫

step 1. 建立專案

注意檔案結構!

上一篇已經建立好 laradock 的專案資料夾,裡面有 laradock。現在要再建立兩個給前後端的資料夾。

專案資料夾
|-be <- 要用來放 Laravel 
|-js <- 要用來放 Angular 
|-laradock

進去專案資料夾去 clone 或 create 你的專案。

專案資料夾
|-be
|---public
|-----index.php
|-js
|---public
|-----index.html
|-laradock
|---nginx
|-----.env
|-----sites
|-------be.conf
|-------js.conf

step 2. 設定 nginx/.env

保持不動,在laradock同級目錄

step 3. 設定 nginx/sites/[projectName].conf

D:\docker\laradock\nginx\sites
新增內容,可以從 .example 改。nginx.conf 會 include

要改兩個地方
1.root
root /var/www/[專案名稱]/[放index的資料夾通常是public];
2.server_name
/ect/hosts 要對應的名稱

js.conf

server {
    listen 80;
    listen [::]:80;

    server_name js;
    root /var/www/js/public;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }
}

be.conf

server {
    listen 80;
    listen [::]:80;

    server_name be;
    root /var/www/be/public;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }
}

step 4. 改 /ect/hosts

  • 開資料夾 C:\Windows\System32\drivers\etc
  • 改 hosts 加上這兩段對應前面 .conf 的 servername
127.0.0.1 js
127.0.0.1 be

step 5. 運行 laradock 和瀏覽器

docker-compose exec workspace bash

開瀏覽器檢查

http://js:5566/
http://be:5566/

step 6. 連結資料庫

如果是 mysql
BD_HOST 改成 localhost

參考


#Laravel #laradock







Related Posts

Redux, useSelector, useDispatch

Redux, useSelector, useDispatch

筆記、LIOJ

筆記、LIOJ

Day 03:  GraphQL and GiHub GrapQL - Operations, Variables, and Mutations

Day 03: GraphQL and GiHub GrapQL - Operations, Variables, and Mutations


Comments