我正在运行一个需要PHP 5.6的旧版Laravel项目,并且正在使用Laravel Homestead运行旧版的PHP。
对于开发环境,我正在尝试配置nginx以便将网站上使用的图像URL重写到生产服务器,因此我不必下载资产即可在本地查看网站。
以前,我曾使用以下nginx位置规则重写URL:
location ~ ^/en/images/(.*) {
rewrite ^/en/images/(.*)$ https://live.website/en/images/$1 last;
}
为了让Homestead保留自定义nginx配置,我不得不在Homestead / scripts目录中创建一个serve-custom.sh文件,并将其设置在我的Homestead.yaml文件中。
我的serve-custom.sh文件看起来像这样
declare -A params=$6 # Create an associative array
paramsTXT=""
if [ -n "$6" ]; then
for element in "${!params[@]}"
do
paramsTXT="${paramsTXT}
fastcgi_param ${element} ${params[$element]};"
done
fi
if [ "$7" = "true" ] && [ "$5" = "7.2" ]
then configureZray="
location /ZendServer {
try_files \$uri \$uri/ /ZendServer/index.php?\$args;
}
"
else configureZray="" .
fi
block="server {
listen ${3:-80};
listen ${4:-443} ssl http2;
server_name .$1;
root \"$2\";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
$configureZray
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;
client_max_body_size 100m;
location ~ ^/en/images/(.*) {
rewrite ^/en/images/(.*)$ https://live.website/en/images/$1 last;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php$5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
$paramsTXT
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/$1.crt;
ssl_certificate_key /etc/nginx/ssl/$1.key;
}
"
echo "$block" > "/etc/nginx/sites-available/$1"
ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
我遇到的问题是,在Chrome的DevTools中查看时,将插入实际的nginx服务器名称,而不是请求的文件/资产。
希望这一切都有道理。感谢您的任何提前帮助。