(1)Nginx安裝配置html
① 下載Nginx 安裝 linux
wget -c http://nginx.org/download/nginx-1.12.0.tar.gz nginx
② 解壓安裝包c++
tar -xzf nginx-1.12.0.tar.gzshell
③ 進入源碼目錄vim
cd nginx-1.12.0bash
④ 進入源碼目錄,預編譯,編譯 ,安裝dom
useradd wwwide
./configure --prefix=/usr/local/nginx --user=www --group=www測試
註釋:
若是在編譯的過程當中,報.configure:error :c complier cc is not found
解決辦法是yum install gcc gcc-c++
若是在編譯的過程當中,報./configure: error: the HTTP rewrite module requires the PCRE library.
解決辦法是yum install pcre-devel
若是在編譯的過程當中,報/configure: error: the HTTP gzip module requires the zlib library.
解決辦法是yum install -y zlib-devel
完了,執行make make install
⑤ nginx配置文件組成剖析
nginx配置文件由conf html logs sbin組成
conf目錄,存放的是配置文件
html目錄,是網站發佈目錄
logs是日誌目錄
sbin目錄,是存放命令的目錄
⑥ 關閉selinux 和防火牆
setenfroce 0 service iptabltes stop
⑦ 啓動nginx
/usr/local/nginx/sbin/nginx
⑧ 查看端口和進程是否啓動
ps -ef |grep nginx netstat -ntl|grep 80
⑨ 修改nginx發佈目錄
進入 cd /usr/local/nginx/html
在html目錄下,有一個index.html文件,修改它,便可
重啓nginx /usr/local/nginx/sbin/nginx -s reload
⑩ 中止nginx /usr/local/nginx/sbin/nginx -s stop
⑪ nginx開機自啓動 把須要開機自啓動相對內容寫到/etc/rc.local配置文件中
⑫ /usr/local/nginx/sbin/nginx -v 查看nginx版本信息
⑬ /usr/local/nginx/sbin/nginx -V 查看nginx參數信息
⑭ nginx虛擬主機的配置
<1>去除nginx.conf配置文件中的#號,空格 grep -v "#" nginx.conf | grep -v "^$">>nginx.conf.swp
<2>打開vim nginx.conf配置文件,找到server配置段
server {
listen 80;
server_name www.jf1.com;
location / {
root html;
index index.html index.htm;
}
}
註釋:
<1> server_name 爲網站的域名
<2> 網站上的index.html默認存放在html目錄根目錄下,也能夠修改成html /www.jf1.com 在這個目錄下建立index,html文件
<3> 有幾個網站就配置幾個server段
<4> server段配置,也能夠從nginx.conf單獨出來,在nginx配置文件中,把server段放在vhosts目錄下,在http配置段中加入include vhosts/*
⑮ nginx升級
<1> 下載新版本的nginx源碼文件,解壓,進入源碼編譯目錄,預編譯,編譯
<2> 備份舊版本的nginx可執行文件 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
<3> cp objs/nginx /usr/local/nginx/sbin
<4> 測試新版本的nginx是否正常
/usr/local/nginx/sbin/nginx -t
<5> 驗證nginx升級是否成功
/usr/local/nginx/sbin -V
shell 腳本自動化安裝nginx v1版
#!/bin/bash #2018年1月4日15:03:09 #auto_config_nginx #by author daqi ############### #### nginx start #### setenforce 0 service iptables stop yum install gcc gcc-c++ -y yum install pcre-devel -y yum install zlib-devel -y wget -c http://nginx.org/download/nginx-1.12.0.tar.gz tar -xzf nginx-1.12.0.tar.gz useradd www -s /sbin/nologin cd nginx-1.12.0 ./configure --prefix=/usr/local/nginx/ --user=www --group=www make make install /usr/local/nginx/sbin/nginx ps -ef |grep nginx netstat -ntlup | grep 80 ### nginx end ### ### vitural host start ### cd /usr/local/nginx/conf grep -vE "#|^$" nginx.conf >> nginx.conf.swp sed -i '/server/,$d' nginx.conf.swp echo "include domains/*;" >> nginx.conf.swp echo "}" >> nginx.conf.swp \mv nginx.conf.swp nginx.conf mkdir -p domains cd domains cat>www.jf1.com<<EOF server { listen 80; server_name www.jf1.com; location / { root html/www.jf1.com; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } EOF mkdir -p /usr/local/nginx/html/www.jf1.com cat>/usr/local/nginx/html/www.jf1.com/index.html<<EOF <h1>welcome to nginx</h1> <h2>www.jf1.com</h2> EOF /usr/local/nginx/sbin/nginx -s reload |
auto_nginx_v2.sh #!/bin/bash #2018年1月4日15:03:09 #auto_config_nginx #by author daqi ############### #### nginx start #### NGINX_LIB="gcc gcc-c++ pcre-devel zlib-devel" NGINX_URL="http://nginx.org/download" NGINX_TARGET="1.12.0" NGINX_SOFT="nginx-${NGINX_TARGET}.tar.gz" NGINX_SRC="nginx-${NGINX_TARGET}" NGINX_DIR="/usr/local/nginx" NGINX_CONF="nginx.conf" NGINX_DOMAINS="$*" setenforce 0 service iptables stop yum install $NGINX_LIB -y wget -c $NGINX_URL/$NGINX_SOFT tar -xzf $NGINX_SOFT useradd www -s /sbin/nologin cd $NGINX_SRC ./configure --prefix=$NGINX_DIR/ --user=www --group=www make make install $NGINX_DIR/sbin/nginx ps -ef |grep nginx netstat -ntlup | grep 80 ### nginx end ### ### vitural host start ### cd $NGINX_DIR/conf grep -vE "#|^$" $NGINX_CONF >> $NGINX_CONF.swp sed -i '/server/,$d' $NGINX_CONF.swp echo "include domains/*;" >> $NGINX_CONF.swp echo "}" >> $NGINX_CONF.swp \mv $NGINX_CONF.swp $NGINX_CONF mkdir -p domains cd domains cat>$NGINX_DOMAINS<<EOF server { listen 80; server_name $NGINX_DOMAINS; location / { root html/$NGINX_DOMAINS; index index.html index.htm; }
} EOF mkdir -p $NGINX_DIR/html/$NGINX_DOMAINS cat>$NGINX_DIR/html/$NGINX_DOMAINS/index.html<<EOF <h1>welcome to nginx</h1> <h2>$NGINX_DOMAINS</h2> EOF $NGINX_DIR/sbin/nginx -s reload |
auto_nginx_v3.sh #!/bin/bash #2018年1月4日15:03:09 #auto_config_nginx #by author daqi ############### #### nginx start #### NGINX_LIB="gcc gcc-c++ pcre-devel zlib-devel" NGINX_URL="http://nginx.org/download" NGINX_TARGET="1.12.0" NGINX_SOFT="nginx-${NGINX_TARGET}.tar.gz" NGINX_SRC="nginx-${NGINX_TARGET}" NGINX_DIR="/usr/local/nginx" NGINX_CONF="nginx.conf" NGINX_DOMAINS="$*" if [ $# -eq 0 ];then echo -e "\033[32mUsage:{/bin/sh $0 v1.jf.com|v2.jf.com v3.jf.com}\033[0m" exit 0 fi if [ ! -f $NGINX_DIR/sbin/nginx ];then setenforce 0 service iptables stop yum install $NGINX_LIB -y wget -c $NGINX_URL/$NGINX_SOFT tar -xzf $NGINX_SOFT useradd www -s /sbin/nologin cd $NGINX_SRC ./configure --prefix=$NGINX_DIR/ --user=www --group=www make make install $NGINX_DIR/sbin/nginx ps -ef |grep nginx netstat -ntlup | grep 80 fi ### nginx end ### ### vitural host start ### cd $NGINX_DIR/conf grep "include domains" $NGINX_CONF>/dev/null if [ $? -ne 0 ];then grep -vE "#|^$" $NGINX_CONF >> $NGINX_CONF.swp sed -i '/server/,$d' $NGINX_CONF.swp echo "include domains/*;" >> $NGINX_CONF.swp echo "}" >> $NGINX_CONF.swp \mv $NGINX_CONF.swp $NGINX_CONF mkdir -p domains fi cd domains for NGINX_DOMAINS in `echo $NGINX_DOMAINS` do if [ ! -f $NGINX_DOMAINS ];then cat>$NGINX_DOMAINS<<EOF server { listen 80; server_name $NGINX_DOMAINS; location / { root html/$NGINX_DOMAINS; index index.html index.htm; }
} EOF mkdir -p $NGINX_DIR/html/$NGINX_DOMAINS cat>$NGINX_DIR/html/$NGINX_DOMAINS/index.html<<EOF <h1>welcome to nginx</h1> <h2>$NGINX_DOMAINS</h2> EOF fi done $NGINX_DIR/sbin/nginx -t >/dev/null 2>&1 if [ $? -eq 0 ];then $NGINX_DIR/sbin/nginx -s reload else $NGINX_DIR/sbin/nginx -t |