下載 官網下載地址:http://nginx.org/en/download.html Mainline version 開發版Stable version 穩定版Legacy versions 歷史版 滑鼠移動到你要選擇的版本超鏈接上點右鍵 複製鏈接地址 下載:wget http://nginx. ...
下載
官網下載地址:http://nginx.org/en/download.html
Mainline version 開發版
Stable version 穩定版
Legacy versions 歷史版
滑鼠移動到你要選擇的版本超鏈接上點右鍵 複製鏈接地址
下載:wget http://nginx.org/download/nginx-1.22.1.tar.gz洗
下載之後扔到/usr/local下
安裝
安裝:yum -y install pcre-devel openssl openssl-devel
解壓:tar -zxvf nginx-1.22.1.tar.gz
進去:cd cd nginx-1.22.1/
配置:./configure --with-http_stub_status_module --with-http_ssl_module
安裝:make && make install
配置
打開配置文件:vim /usr/local/nginx/conf/nginx.conf
一個監聽是一個server{....}段落,裡面預設的server代碼塊可以刪掉。
當你在你的功能變數名稱控制台(阿裡雲或騰訊雲或百度雲等等)中設置功能變數名稱解析成當前伺服器IP時,你就可以在這裡配置功能變數名稱監聽。
比如下麵這段:
server { listen 80; server_name www.abc.com abc.com; root /www/abc; location / { index.html; } }
當瀏覽器訪問 www.abc.com時,由於功能變數名稱解析指向當前伺服器,所以網路請求會發往當前伺服器的80埠,nginx監聽到請求後,會去找到root指定的地址 也就是/www/abc目錄,將目錄中的index.html返回給請求方,此時瀏覽器收到返回,解析標簽,展示在頁面上。
命令
編寫服務腳本:vim /etc/init.d/nginx
粘貼以下代碼:
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /usr/local/nginx/logs/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
PS:經常粘貼前兩行貼不全,小心檢查。
設置許可權:chmod 755 /etc/init.d/nginx
自啟配置:vim /etc/rc.local
在文件末尾新增一行:/usr/local/nginx/sbin/nginx
開機自啟:chkconfig nginx on
可使用的命令:
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl reload nginx
systemctl restart nginx