linux下如何新增子域名
本文目錄:
1.域名解析配置
2.伺服器配置
1.子域名解析
找到域名商,設定解析

如圖,主機記錄填寫子域名名稱
2.伺服器配置
首先在conf檔案中增加一個server{},可直接複製之前的程式碼,只需要修改其中加粗部分欄位:
server {listen 80;server_name 子域名.域名.com ;index index.html index.htm index.php;root 子域名的目錄地址; include /etc/nginx/default.d/*.conf;#php服務的解析,無php服務請刪掉此段程式碼location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PHP_VALUE open_basedir=$document_root:/tmp/:/proc/;include fastcgi_params;}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}
完。
ps:你可可以在conf檔案中加入include conf.d/*.conf,然後在conf檔案的目錄下找到conf.d資料夾中建立xx.conf,將以上程式碼寫入conf檔案中即可。