我想将所有这些回复到文件中:
echo "server {
listen 80;
server_name mydomain.com;
root /srv/www/clients/;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
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/finance-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}" >> default
但是所有包含美元符号的值(如$ query_string;或$ document_root $ fastcgi_script_name;)都将被删除。是否有可能以某种方式逃避它,以便所有这些值也会持久存在于文件中?
答案 0 :(得分:2)
您应该使用单引号来阻止参数扩展,或者您可以使用here-doc:
cat <<'EOF' > default
$query_string
$document_root
$fastcgi_script_name
EOF
(或>> default
,如果你想追加)。请注意引用'EOF'
以防止参数扩展。