内容如下:
#!/usr/bin/env bash
declare -A params=$6 # Create an associative array
declare -A headers=${9} # Create an associative array
declare -A rewrites=${10} # Create an associative array
paramsTXT=""
if [ -n "$6" ]; then
for element in "${!params[@]}"
do
paramsTXT="${paramsTXT}
fastcgi_param ${element} ${params[$element]};"
done
fi
headersTXT=""
if [ -n "${9}" ]; then
for element in "${!headers[@]}"
do
headersTXT="${headersTXT}
add_header ${element} ${headers[$element]};"
done
fi
rewritesTXT=""
if [ -n "${10}" ]; then
for element in "${!rewrites[@]}"
do
rewritesTXT="${rewritesTXT}
location ~ ${element} { if (!-f \$request_filename) { return 301 ${rewrites[$element]}; } }"
done
fi
if [ "$7" = "true" ]
then configureXhgui="
location /xhgui {
try_files \$uri \$uri/ /xhgui/index.php?\$args;
}
"
else configureXhgui=""
fi
block="upstream webman {
server 127.0.0.1:${11};
}
server {
listen ${3:-80};
listen ${4:-443} ssl http2;
server_name .$1;
root \"$2\";
index index.html index.htm index.php;
charset utf-8;
$rewritesTXT
location / {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header Host \$host;
$headersTXT
if (!-f \$request_filename){
proxy_pass http://webman;
}
}
$configureXhgui
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/$1-error.log error;
sendfile off;
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/ssl/certs/$1.crt;
ssl_certificate_key /etc/ssl/certs/$1.key;
}
"
echo "$block" > "/etc/nginx/sites-available/$1"
ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
Homestead/scripts/homestead.rb
,新增 upstreamPort
配置,传递给脚本的第 11 个变量。在 378 行左右。<...>
# Convert the site & any options to an array of arguments passed to the
# specific site type script (defaults to laravel)
s.path = script_dir + "/site-types/#{type}.sh"
s.args = [
site['map'], # $1
site['to'], # $2
site['port'] ||= http_port, # $3
site['ssl'] ||= https_port, # $4
site['php'] ||= '8.0', # $5
params ||= '', # $6
site['xhgui'] ||= '', # $7
site['exec'] ||= 'false', # $8
headers ||= '', # $9
rewrites ||= '', # $10 注意,这里要增加 ","
site['upstream_port'] ||= '8787', # $11 这里是新增的
]
<...>
<...>
sites:
<...>
- map: webman.test
to: /home/vagrant/code/php/webman-test/public
php: "8.0"
type: webman
upstream_port: 8788 # 此处指定 upstream 中的 port;
<...>
<...>
192.168.10.10 webman.test
<...>
vagrant provision
,重新生成站点配置。webman/config/server.php
,监听端口需与 upstreamPort 相同。php start.php start
,启动项目。webman.test
,查看项目是否配置成功。
感谢分享
@walkor 不支持粘贴图片上传吗?
编辑器支持截图粘贴,直接ctrl v。评论类的建议输入框不支持粘贴截图。
在发布分享的编辑器截图粘贴失败了。
回头我看下
评论处不能粘贴,发布分享处不能粘贴,评论下方的发布回答处可以粘贴。
给 homestead 提交了建议,看你看是否可能愿意新增 webman 的站点创建: https://github.com/laravel/homestead/issues/1764
非常感谢 👍
https://github.com/laravel/homestead/pull/1766 已添加相关 type site。待合并。后续可以直接使用 homestead 作为开发环境了