Skip to content

Instantly share code, notes, and snippets.

@ikbear
Created January 8, 2011 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikbear/770859 to your computer and use it in GitHub Desktop.
Save ikbear/770859 to your computer and use it in GitHub Desktop.
在服务器上添加一个网站,服务器为nginx,本脚本功能为添加网站的配置文件
#!/bin/bash
# Usage:
# ./server.sh domain.com(without www)
# ./server.sh helishi.net
if [ "$*" = "" ]
then
exit;
fi
server="server {\n
\tlisten 80;\n
\tserver_name www.$* $*;\n
\tclient_max_body_size 20M;\n\n
\tlocation / {\n
\t\troot /home/ikbear/www/$*;\n
\t\tindex index.html index.htm index.php;\n
\t\tif (!-e \$request_filename){\n
\t\t\trewrite ^.*$ /index.php last;\n
\t\t}\n
\t\tcharset utf-8,gbk;\n
\t}\n\n
\tif (\$http_host ~* \"^$*\"){\n
\t\tset \$rule_0 1\$rule_0;\n
\t}\n
\tif (\$rule_0 = \"1\"){\n
\t\trewrite ^/(.*)$ http://www.$*/\$1 permanent;\n
\t\tbreak;\n
\t}\n\n
\t# pass the PHP scripts to FastCGI server listening on
var/run/php-fpm.sock\n
\tlocation ~ \.php$ {\n
\t\tautoindex on;\n
\t\troot /home/ikbear/www/$*/;\n
\t\tfastcgi_pass 127.0.0.1:9000;\n
\t\tfastcgi_index index.php;\n
\t\tfastcgi_param SCRIPT_FILENAME /home/ikbear/www/$*
\$fastcgi_script_name;\n
\t\tinclude fastcgi_params;\n
\t}\n
}\n"
mkdir /home/ikbear/www/$*
echo -e $server > /etc/nginx/sites-available/$*
ln -s /etc/nginx/sites-available/$* /etc/nginx/sites-enabled/$*
service nginx restart
echo "All DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment