CentOS7+Nginx1.95+mariadb10.0.21+php5.6.14
1.查看系统版本
root@XiaoFeng html]#cat /etc/centos-release
CentOS Linux release 7.1.1503
本文直接禁用掉了防火墙firewalld和selinux:
systemctl mask firewalld 禁用防火墙
systemctl stop firewalld 停止防火墙
vim /etc/selinux/config
SELINUX=enforcing 改成 SELINUX=disabled
2.安装一些必要的组件
[root@XiaoFeng /]# yum -y install libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl openssl-devel libtool-ltdl-devel gcc gcc-c++* ncurses ncurses-devel
1 2 3 4 5 6 7 8 9 10 11 12 13
| [root@XiaoFeng ~]# wget http: [root@XiaoFeng lnmp]# tar -zxvf pcre-8.37.tar.gz [root@XiaoFeng lnmp]# cd pcre-8.37 [root@XiaoFeng pcre-8.37]# ./configure [root@XiaoFeng pcre-8.37]# make && make install [root@XiaoFeng html]# yum -y install pcre-devel [root@XiaoFeng lnmp]# tar -zxvf nginx-1.9.5.tar.gz [root@XiaoFeng lnmp]# cd nginx-1.9.5 [root@XiaoFeng nginx-1.9.5]# useradd -s /sbin/nologin nginx [root@XiaoFeng nginx-1.9.5]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-sha1=/usr/lib [root@XiaoFeng nginx-1.9.5]# make && make install [root@XiaoFeng /]# cd /usr/local/nginx/sbin/ [root@XiaoFeng /]# ./nginx
|
3.添加Nginx开机启动(centos7新加的启动方式)
启动脚本
vim /usr/lib/systemd/system/nginx.service
#输入下面内容,并保存
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target
[Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true
[Install] WantedBy=multi-user.target
|
#保存为nginx.service
4.修改权限
[root@XiaoFeng /]#chmod +x /usr/lib/systemd/system/nginx.service
5.开机启动
[root@XiaoFeng /]#systemctl enable nginx.service
#现在可以使用下面的指令来控制nginx啦
1 2 3 4
| $ systemctl start nginx.service $ systemctl reload nginx.service $ systemctl restart nginx.service $ systemctl stop nginx.service
|
6.查看日志
[root@XiaoFeng /]#journalctl -f -u nginx.service
#注意上面的几个路径,下面这几个路径是你的nginx安装的目录,务必不要弄错。
1 2 3
| PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
|
7.启动服务
[root@XiaoFeng ~]# systemctl start nginx.service
8.老的方法启动脚本
[root@XiaoFeng lnmp]#vim /etc/init.d/nginx
复制下面内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #!/bin/sh
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx
start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval }
stop() { echo -n $"Stopping $prog: " killall nginx -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx }
restart() { configtest || return $? stop sleep 1 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 2 esac
|
添加执行权限
[root@XiaoFeng lnmp]# chmod 755 /etc/init.d/nginx
[root@XiaoFeng lnmp]# service nginx start
如果想让它开机启动,执行:(两种启动用一种即可)
[root@XiaoFeng lnmp]# chkconfig nginx on
查看是否开机启动:
[root@XiaoFeng lnmp]# chkconfig --list nginx
nginx 0:关 1:关 2:开 3:开 4:开 5:开 6:关
本文为 小风原创文章,转载无需和我联系,但请注明来自 小风博客www.hotxf.com
打 赏