0

私は次のような設定ファイルのセクションを見つけて置き換える方法を知っています:

sudo sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 3M/" /etc/php5/cgi/php.ini

しかし、bashスクリプト内の構成ファイルの最後にまったく新しいセクションを追加するにはどうすればよいですか?

server {
    listen      xx.xx.xx.xx:80;                # your server's public IP address
    server_name  myapp.com;                   # your domain name
    root         /usr/share/nginx/www/myapp/;  # absolute path to your WordPress installation    
}

ターミナル内でこれを試しましたecho "server { ... }" >> nginx.confが、

-bash: nginx.conf: Permission denied

これがbashスクリプト内で問題ないのか、それとも許可が再度拒否されるのかわからない...

4

2 に答える 2

0

これを試して:

config="server {\n    listen      xx.xx.xx.xx:80;\n     server_name  myapp.com;               \n    root         /usr/share/nginx/www/myapp/;  =installation    \n }\n"
 in1="text_before_required_input"
 out1=`echo -e $config`;
              in=$in1 out=$out1 perl -pi.nk -e 's/\Q$ENV{"in"}/$ENV{"out"}/g'  file

上記でない場合は、GNU ed http://wiki.bash-hackers.org/howto/edit-edを調べてください。

于 2012-10-23T15:23:11.773 に答える
0

You are using the right syntax.

echo "....." >> ngix.conf

Just make sure you have the correct write permissions for 'ngix.conf'.

-bash: nginx.conf: Permission denied

This indicates that you have no write privileges.

You can also write the section in an single file like 'new_section.txt' and late add it with:

cat new_section.txt >> ngix.conf

However I would not advise to add configurations to ngix in this way. You can use the 'include' statement.

include you_conf_path/my_new_config.conf;

This way you can group the configuration and have some small config files and not one huge file. Then you can also name your file in a way that helps you find the right one.

于 2012-10-23T13:14:29.480 に答える