Welcome! Log In Create A New Profile

Advanced

Bash shell install/upgrade script for nginx / CentOS 5.5 based ?

Posted by George 
Bash shell install/upgrade script for nginx / CentOS 5.5 based ?
December 25, 2010 06:54AM
I came across bash shell install script for installing nginx as reverse proxy to apache at http://www.doxer.org/learn-linux/centos-nginx-reverse-server/.

I ended up modifying it (very bottom of thread) for my own tastes haven't tested it to see if it works.

But was wondering anyone got bash shell install and upgrade script for full apache replacement, nginx 0.8.x + php 5.3.4 php-fpm ? Would be interested in seeing the different ways in which others folks do these install/upgrades as after a while I am getting tired of doing it manually LOL

[code]
#!/bin/bash
#nginx_reverse_proxy_centos.sh
#by doxer.org
os="";
grep "centos" /etc/issue -i -q
if [ $? = '0' ];then
os='centos'
fi

grep "debian" /etc/issue -i -q
if [ $? = '0' ];then
os='debian'
fi

if [ $os = "" ];then
echo "not a valid system os"
exit 1
fi
#set variables begin
downloads="/usr/local/src/nginx"
vhostpath="/usr/local/nginx/conf/vhosts"

#set variables end

#centos begin
rpm -qa|grep httpd #under centos it's httpd,debian apache
if [ $? = '0' ];then
aa="`rpm -qa|grep httpd`"
rpm -e $aa
fi

yum -y install gcc gcc-c++ zlib-devel openssl-devel zlib zlib-devel gd gd-devel pcre pcre-devel #expect Is this ok =>y
if [ ! -d $downloads ];then
mkdir $downloads
fi
cd $downloads #pwd /usr/local/src/nginx

cd .. #pwd /usr/local/src/nginx
#install nginx begin
wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar zxvf nginx-0.8.54.tar.gz
mkdir -p /usr/local/nginx
cp -R ./nginx-0.8.54/* /usr/local/nginx
cd /usr/local/nginx #pwd /usr/local/nginx

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-http_secure_link_module --with-http_flv_module --with-openssl=/usr/lib/openssl --with-http_sub_module option

make && make install
mkdir -p /usr/local/nginx/logs
chmod +w /usr/local/nginx/logs
groupadd nginx
useradd -g nginx nginx
chown -R nginx:nginx /usr/local/nginx/logs
touch /usr/local/nginx/conf/proxy.conf

if [ ! -d $vhostpath ];then
mkdir $vhostpath

echo "proxy_redirect off;
proxy_set_header Host \$host;
proxy_set_header Port \$proxy_port;
proxy_set_header XHost \$host:\$proxy_port;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header REMOTE_ADDR \$remote_addr;
proxy_set_header HTTP_CLIENT_IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
#client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
proxy_buffer_size 16k;
expires 60;
client_body_timeout 60;
client_header_timeout 60;">/usr/local/nginx/conf/proxy.conf
rm -f /usr/local/nginx/conf/nginx.conf
touch /usr/local/nginx/conf/nginx.conf
echo -e 'user nginx nginx;
worker_processes 2;
error_log /usr/local/nginx/logs/error.log crit;
pid /usr/local/nginx/nginx.pid;

events {
use epoll;
worker_connections 1024;
multi_accept on;
}

http {
include mime.types;
include proxy.conf;
default_type application/octet-stream;
charset utf-8;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;

gzip on;
gzip_static on;
gzip_min_length 1100;
gzip_buffers 32 8k;
gzip_http_version 1.0;
gzip_comp_level 1;
gzip_proxied any;
gzip_types text/plain text/css text/javascript text/xml application/x-javascript application/xml application/xml+rss;
gzip_vary on;

include /usr/local/nginx/conf/vhosts/*.conf;

upstream localhost{
server 127.0.0.1:81;
}

server{
listen 80;
server_name _;
location / {
proxy_pass http://localhost;
}
}

server {
listen 80;
server_name _;
location / {
if ($host !~* www\.(.*)) {
set $host_without_www $1;
set $xhost www.$host;
rewrite ^(.*)$ http://$xhost$host_without_www$1 permanent;
}
proxy_pass http://localhost;
}

location /ns {
stub_status on;
access_log off;
# allow _STUFFIP_;
# allow _SERVERIP_;
# allow 127.0.0.1;
# deny all;
}
location ~ /\.ht {
deny all;
}
}
}'>/usr/local/nginx/conf/nginx.conf
#install nginx end

/usr/local/nginx/sbin/nginx #start nginx
ps aux|grep nginx|grep grep #check if nginx running now
if [ $? = '0' ];then
echo "nginx is running now"
else
echo "not running"
fi
#centos end
[/code]
Re: Bash shell install/upgrade script for nginx / CentOS 5.5 based ?
May 25, 2011 03:10AM
well found such a bash shell install script http://vbtechsupport.com/796/ :)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 286
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready