【发布时间】:2021-10-08 13:33:12
【问题描述】:
这就是我通过 shell 创建文件 (nginx.conf) 的方式。
因为文件内容中有$ 字符,所以我使用EOF。
if [ $type == "nginx" ]; then
cat > ${path}/nginx.conf <<'EOF'
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
include /etc/nginx/extra-conf.d/*.conf;
}
EOF
fi
现在我必须使用动态端口值,所以我需要使用listen $port 而不是listen 3000。
但这行不通,因为内容中还有$uri,应该作为文本处理,而不是作为变量处理。
【问题讨论】: