:::

8-2 啟用使用者目錄

  1. 編輯設定檔
    vi /etc/nginx/sites-available/default 

     

  2. server{}中加入:
      location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html$2;
        index  index.html index.htm index.php;
        autoindex on;
      }

     

  3. 至此,已經支援使用者家目錄網頁。可建立新使用者並測試之。
    adduser somebody

     

  4. 建立使用者網頁目錄
    mkdir /home/somebody/public_html

     

  5. 建立網頁檔:
    vi /home/somebody/public_html/index.html

     

  6. 其內容為:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        網頁已開通!
    </body>
    </html>

     

  7. 接著讓使用者加目錄網頁也可以支援PHP,編輯設定檔
    vi /etc/nginx/sites-available/default 

     

  8. server{}中的location ~ ^/~(.+?)(/.*)?$ {上方加入:
      location ~* ^/~(.+?)(/.*\.php)$ {
        alias /home/$1/public_html$2;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
      }
    
      location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html$2;
        index  index.html index.htm index.php;
        autoindex on;
      }

     

  9. 重啟伺服器即可
    systemctl restart nginx 

     


:::

書籍目錄

展開 | 闔起

http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D15%26tbdsn%3D1546

計數器

今天: 4863486348634863
昨天: 3438343834383438
總計: 7395192739519273951927395192739519273951927395192