前一段時(shí)間打算嘗試一下微信開(kāi)發(fā),需要在阿里云上使用多個(gè)項(xiàng)目祈纯,于是查了一下資料令宿,找到如下實(shí)現(xiàn)方案:
利用nginx泛域名解析配置二級(jí)域名和多域名
網(wǎng)站的目錄結(jié)構(gòu)為
code
├── www
└── bbs
code為nginx的安裝目錄下默認(rèn)的存放源代碼的路徑。
www為主頁(yè)程序源代碼路徑
bbs為論壇程序源代碼路徑
把相應(yīng)程序放入上面的路徑通過(guò)
http://www.youdomain.com 訪問(wèn)的就是主頁(yè)
http://bbs.yourdomain.com 訪問(wèn)的就是論壇
其它二級(jí)域名類推腕窥。
具體配置如下粒没,找到/etc/nginx/sites-available/default文件,修改為如下:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/$subdomain/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name ~^(?<subdomain>.+).yourdomain.com$;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
接著解析域名簇爆,到對(duì)應(yīng)的域名管理處新增加子域名的解析癞松,添加一條記錄。記錄類型為A入蛆,主機(jī)記錄為你的子域名(對(duì)應(yīng)上面的目錄)响蓉,記錄值為ip地址,其他保持默認(rèn)即可哨毁。同時(shí)枫甲,如果之前添加了@或空的主機(jī)記錄,記得刪除扼褪,以免產(chǎn)生混淆想幻。
重啟nginx,等待域名解析生效即可话浇。
其他問(wèn)題:
如果按照上面的步驟后出現(xiàn)500錯(cuò)誤举畸,可能是Laravel沒(méi)有對(duì)應(yīng)的存儲(chǔ)權(quán)限導(dǎo)致的,可以使用下面的命令來(lái)給storage賦予權(quán)限chmod -R 777 storage
參考資料