說明: 通過 brew 安裝的 nginx
網站根目錄: /opt/homebrew/var/www
nginx 配置目錄: /opt/homebrew/etc/nginx/
假設: 有項目名稱為 TestProject , 域名為 bd.testproject.com
第一步 : 設置 IP 與 域名 映射 (也就是增加 hosts)
# 終端
vim /etc/hosts
# 增加保存
127.0.0.1 bd.testproject.com
第二步 : 新建站點配置文件目錄
# 終端
mkdir /opt/homebrew/etc/nginx/vhosts
第三步 : 新建站點配置文件
在 /opt/homebrew/etc/nginx/vhosts 目錄中新建名為 bd.testproject.com_80.conf 配置文件 , 配置文件內容為(可根據自需更改配置內容):
server {
listen 80;
server_name bd.testproject.com;
root "/opt/homebrew/var/www/bd.testproject.com";
location / {
index index.php index.html error/index.html;
autoindex off;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
第四步 : 在 nginx 默認配置文件中引入站點配置
# 終端
vim /opt/homebrew/etc/nginx/nginx.conf
# 在文件內 http{} 中新增
server_names_hash_bucket_size 64; # 修改服務器名稱長度,只能為 32 的倍數
include /opt/homebrew/etc/nginx/vhosts/*; # 引入站點配置
第五步 : 重啟 nginx
請忽略我, 啟動 fastcgi
/usr/local/php/bin/php-cgi -b 9000
到此這篇關于Mac M1 Nginx 配置多站點的實現的文章就介紹到這了,更多相關Mac M1 Nginx多站點內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!