Created
July 14, 2019 16:20
-
-
Save jk2K/542aa8654e5279d4f5e32667bcf13c5d to your computer and use it in GitHub Desktop.
安装 nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
local_archive_path=$1 | |
function get_filename_from_url() { | |
download_url=$1 | |
file_with_query_params=$(echo "${download_url##*/}") | |
file=$(echo "${file_with_query_params%%\?*}") | |
echo ${file} | |
} | |
download_url='http://xx.com/nginx-1.15.8.tgz?url=aHR0cDovL3N0b3JhZ2UuamQuY29tL2F2YXRhci1wb2MvYmFzaWMvbmdpbngtMS4xNS44LnRnej9FeHBpcmVzPTE1NjE5ODUzMDImQWNjZXNzS2V5PTZBd0xncTl1M3RRZG5yQzYmU2lnbmF0dXJlPUE2NGRrY2NhMUdocllHWml4RyUyQjlaRU54MGpnJTNE' | |
filename=$(get_filename_from_url ${download_url}) | |
filename_no_ext=$(echo "${filename%.*}") | |
echo ${filename} | |
echo ${filename_no_ext} | |
function download_nginx() | |
{ | |
if [[ -z "${local_archive_path}" ]]; then | |
# 非本地安装 | |
echo "No argument supplied" | |
cd /export/servers | |
#download Nginx | |
wget -q ${download_url} -O ${filename} | |
if [[ $? -eq 0 ]]; then | |
echo -e "\033[42m ######Download Nginx Successful###### \033[0m" | |
else | |
echo -e "\033[31m ######Download Nginx Error,Pls Check!!!###### \033[0m" | |
exit | |
fi | |
else | |
# 本地安装 | |
download_url=${local_archive_path} | |
filename=$(get_filename_from_url ${download_url}) | |
filename_no_ext=$(echo "${filename%.*}") | |
cp ${local_archive_path} /export/servers | |
fi | |
} | |
function install_nginx() | |
{ | |
ls /export/servers | grep nginx | |
if [ $? -eq 0 ]; then | |
echo -e "\033[31m ######Nginx Already Installed,Pls Check!!!###### \033[0m" | |
exit | |
else | |
echo -e "\033[42m ######Ngnix NOT Installed,Begin Install###### \033[0m" | |
fi | |
echo -e "\033[42m ######Start Download Nginx###### \033[0m" | |
download_nginx | |
cd /export/servers | |
#untar Nginx | |
tar xzf ${filename} | |
if [ $? -eq 0 ]; then | |
echo -e "\033[42m ######unTar Nginx Successful###### \033[0m" | |
else | |
echo -e "\033[31m ######unTar Nginx Error,Pls Check!!!###### \033[0m" | |
exit | |
fi | |
sudo mkdir -p /dev/shm/nginx_temp/client_body | |
sudo mkdir -p /dev/shm/nginx_temp/proxy | |
#configure nginx | |
cd "/export/servers/${filename_no_ext}" | |
./configure --prefix=/export/servers/nginx --with-ld-opt=-Wl,-rpath,/usr/local/lib --with-http_ssl_module --sbin-path=/export/servers/nginx/sbin/nginx --conf-path=/export/servers/nginx/conf/nginx.conf --error-log-path=/export/servers/nginx/logs/error.log --http-log-path=/export/servers/nginx/logs/access.log --pid-path=/export/servers/nginx/var/nginx.pid --lock-path=/export/servers/nginx/var/nginx.lock --http-proxy-temp-path=/dev/shm/nginx_temp/proxy --http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi --user=admin --group=admin --with-cpu-opt=pentium4F --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-stream --with-stream_ssl_module | |
#sudo make nginx | |
sudo make | |
#sudo make install nginx | |
sudo make install | |
#Allow admin use Port 80 | |
sudo chown root.root /export/servers/nginx/sbin/nginx | |
sudo chmod 755 /export/servers/nginx/sbin/nginx | |
sudo chmod u+s /export/servers/nginx/sbin/nginx | |
sudo mkdir -p /export/servers/nginx/run | |
# sudo mkdir conf | |
sudo mkdir -p /export/servers/nginx/conf/domains | |
sudo mkdir -p /export/servers/nginx/conf/tcpreverse | |
#Check Nginx Version | |
/export/servers/nginx/sbin/nginx -v | |
} | |
install_nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment