Nginx1.10.1部署實戰

來源:互聯網
上載者:User

標籤:nginx1.10.1部署實戰

1、系統資訊

[[email protected] ~]# cat /etc/redhat-releaseCentOS release 6.6 (Final)[[email protected] ~]# uname -r2.6.32-504.el6.x86_64[[email protected] ~]# uname -mx86_64[[email protected] ~]# uname -nnginx-server[[email protected] ~]# ifconfig eth0eth0      Link encap:Ethernet  HWaddr 00:0C:29:02:BD:AA          inet addr:192.168.100.131  Bcast:192.168.100.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe02:bdaa/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:55736 errors:0 dropped:0 overruns:0 frame:0          TX packets:9189 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:77355420 (73.7 MiB)  TX bytes:790859 (772.3 KiB)


2、軟體資訊

pcre:pcre-8.39.tar.gzopenssl:openssl-1.0.2a.tar.gzzlib:zlib-1.2.7.tar.gznginx:nginx-1.10.1.tar.gz


3、環境準備

[[email protected] ~]# mkdir /software[[email protected] ~]# ll -d /software/drwxr-xr-x. 2 root root 4096 2017-01-12 16:04 /software/[[email protected] ~]# cd /software/[[email protected] software]# yum -y install lrzsz gd-devel[[email protected] software]# rz[[email protected] software]# lltotal 8624-rw-r--r--. 1 root root  909077 2016-06-01 00:38 nginx-1.10.1.tar.gz-rw-r--r--. 1 root root   29542 2015-04-03 10:42 nginx.vim-rw-r--r--. 1 root root 5262089 2015-03-27 11:01 openssl-1.0.2a.tar.gz-rw-r--r--. 1 root root 2062258 2016-09-26 15:01 pcre-8.39.tar.gz-rw-r--r--. 1 root root  560351 2015-03-27 10:49 zlib-1.2.7.tar.gz


4、安裝pcre支援Regex

[[email protected] software]# tar xvfz pcre-8.39.tar.gz -C /usr/local/src/[[email protected] software]# cd /usr/local/src/pcre-8.39/[[email protected] pcre-8.39]# ./configure --prefix=/usr/local/pcre-8.39[[email protected] pcre-8.39]# make && make install[[email protected] pcre-8.39]# ln -s /usr/local/pcre-8.39/ /usr/local/pcre[[email protected] pcre-8.39]# ll /usr/local/pcrelrwxrwxrwx. 1 root root 21 2017-01-12 16:10 /usr/local/pcre -> /usr/local/pcre-8.39/


5、安裝openssl支援加密訪問

[[email protected] software]# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/[[email protected] software]# cd /usr/local/src/openssl-1.0.2a/[[email protected] openssl-1.0.2a]# ./config --prefix=/usr/local/openssl-1.0.2a[[email protected] openssl-1.0.2a]# make && make install[[email protected] openssl-1.0.2a]# ln -s /usr/local/openssl-1.0.2a/ /usr/local/openssl[[email protected] openssl-1.0.2a]# ll /usr/local/openssllrwxrwxrwx. 1 root root 26 2017-01-12 16:17 /usr/local/openssl -> /usr/local/openssl-1.0.2a/


6、安裝zlib支援壓縮

[[email protected] software]# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/[[email protected] software]# cd /usr/local/src/zlib-1.2.7/[[email protected] zlib-1.2.7]# ./configure --prefix=/usr/local/zlib-1.2.7[[email protected] zlib-1.2.7]# make && make install[[email protected] zlib-1.2.7]# ln -s /usr/local/zlib-1.2.7/ /usr/local/zlib[[email protected] zlib-1.2.7]# ll /usr/local/zliblrwxrwxrwx. 1 root root 22 2017-01-12 16:19 /usr/local/zlib -> /usr/local/zlib-1.2.7/


7、安裝nginx

[[email protected] software]# useradd -s /sbin/nologin -M www[[email protected] software]# id wwwuid=500(www) gid=500(www) groups=500(www)[[email protected] software]# tar xvfz nginx-1.10.1.tar.gz -C /usr/local/src/[[email protected] software]# cd /usr/local/src/nginx-1.10.1/[[email protected] nginx-1.10.1]# ./configure --prefix=/usr/local/nginx-1.10.1 --sbin-path=/usr/local/nginx-1.10.1/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_image_filter_module --with-pcre=/usr/local/src/pcre-8.39/ --with-zlib=/usr/local/src/zlib-1.2.7 --with-openssl=/usr/local/src/openssl-1.0.2a[[email protected] nginx-1.10.1]# make && make install[[email protected] nginx-1.10.1]# ln -s /usr/local/nginx-1.10.1/ /usr/local/nginx[[email protected] nginx-1.10.1]# ll /usr/local/nginxlrwxrwxrwx. 1 root root 24 2017-01-12 16:35 /usr/local/nginx -> /usr/local/nginx-1.10.1/


8、設定檔支援語法檢查

[[email protected] nginx-1.10.1]# mkdir-p ~/.vim/syntax[[email protected] nginx-1.10.1]# mv /software/nginx.vim ~/.vim/syntax[[email protected] nginx-1.10.1]# cat >> ~/.vim/filetype.vim<<EOF> au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/vhost/* set ft=nginx> EOF注釋:修改設定檔自由使用絕對路徑才支援語法檢查


9、編寫控制指令碼

[[email protected] nginx-1.10.1]# vim /etc/init.d/nginx#!/bin/sh## nginx - this script starts and stops the nginxdaemin## chkconfig:   -85 15# description: Nginx is an HTTP(S) server, HTTP(S) reverse #              proxy and IMAP/POP3 proxy server# processname: nginx# config:     /etc/nginx/nginx.conf# pidfile:    /var/run/nginx/nginx.pid # Source function library.. /etc/rc.d/init.d/functions # Source networking configuration.. /etc/sysconfig/network # Check that networking is up.[ "$NETWORKING" = "no" ]&& exit 0 nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/etc/nginx/nginx.conf"lockfile="/var/lock/nginx.lock" start() {    [ -x $nginx] || exit 5    [ -f$NGINX_CONF_FILE ] || exit 6    echo -n$"Starting $prog: "    daemon$nginx -c $NGINX_CONF_FILE    retval=$?    echo    [ $retval -eq0 ] && touch $lockfile    return$retval} stop() {    echo -n$"Stopping $prog: "    killproc$prog -QUIT    retval=$?    echo    [ $retval-eq 0 ] && rm -f $lockfile    return$retval} restart() {    configtest|| return $?    stop    start} reload() {    configtest|| return $?    echo -n$"Reloading $prog: "    killproc$nginx -HUP    RETVAL=$?    echo} force_reload() {    restart} configtest() {  $nginx -t -c$NGINX_CONF_FILE} rh_status() {    status $prog} rh_status_q() {    rh_status>/dev/null 2>&1} case "$1" in    start)       rh_status_q && exit 0        $1        ;;    stop)       rh_status_q || exit 0        $1        ;;   restart|configtest)        $1        ;;    reload)       rh_status_q || exit 7        $1        ;;   force-reload)       force_reload        ;;    status)       rh_status        ;;   condrestart|try-restart)       rh_status_q || exit 0        ;;    *)        echo$"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"        exit 2esac[[email protected] nginx-1.10.1]# chmod +x /etc/init.d/nginx[[email protected] nginx-1.10.1]# ll /etc/init.d/nginx-rwxr-xr-x. 1 root root 1900 2017-01-12 16:41 /etc/init.d/nginx[[email protected] nginx-1.10.1]# chkconfig --level 3 nginx on[[email protected] nginx-1.10.1]# chkconfig --list|grep "nginx"nginx           0:off   1:off   2:off   3:on    4:off   5:off   6:off


10、啟動nginx服務

[[email protected] nginx-1.10.1]# /etc/init.d/nginx startStarting nginx:                                            [  OK  ][[email protected] nginx-1.10.1]# netstat -tnlup|grep "80"tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      27197/nginx[[email protected] nginx-1.10.1]# ps -ef|grep "nginx"|grep -v "grep"root     27197     1  0 16:45 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.confwww      27199 27197  0 16:45 ?        00:00:00 nginx: worker process[[email protected] nginx-1.10.1]# curl http://127.0.0.1<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>    body {        width: 35em;        margin: 0 auto;        font-family: Tahoma, Verdana, Arial, sans-serif;    }</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and support please refer to<a href="http://nginx.org/">nginx.org</a>.<br/>Commercial support is available at<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>

本文出自 “閑來無事嘮嘮嗑” 部落格,請務必保留此出處http://laokebang.blog.51cto.com/12486963/1891487

Nginx1.10.1部署實戰

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.