linux centos nginx安装 开机启动

nginx 下载地址 http://nginx.org/download/

1、nginx依赖环境 gc c++,prce 和openssl

[root@bogon ~]# yum install gcc-c++  
[root@bogon ~]# yum -y install pcre*  
[root@bogon ~]# yum -y install openssl*  
[root@bogon ~]# yum -y install wget

2、下载nginx-1.9.9.tar.gz,可放在 /usr/local/ 目录下

[root@bogon ~]# cd /usr/local/ 
[root@bogon ~]# wget http://nginx.org/download/nginx-1.9.9.tar.gz 

3、解压

[root@bogon ~]#tar -zxvf nginx-1.9.9.tar.gz 

4、进入nginx目录

[root@bogon ~]#cd nginx-1.9.9

5、首先,设置安装目录为 /usr/local/nginx

[root@bogon ~]#./configure --prefix=/usr/local/nginx 

6、开始编译安装

[root@bogon ~]#make
[root@bogon ~]#make install 

7、启动nginx服务,进入安装目录 /usr/local/nginx

[root@bogon ~]#cd /usr/local/nginx/sbin
[root@bogon ~]#./nginx  

8、查看进程

[root@bogon ~]#ps -ef | grep nginx  
  1. root     32150     1  0 13:28 ?        00:00:00 nginx: master process ./nginx  
  2. nobody   32151 32150  0 13:28 ?        00:00:00 nginx: worker process  
  3. root     32154 28494  0 13:28 pts/1    00:00:00 grep nginx  

9、浏览器访问IP地址成功页面

 

10、开机自动启动---配置

10.1、在/etc/init.d/目录下创建 nginx 文件,内容如下:

#进入文件夹
cd /etc/init.d/ #创建nginx文件
touch nginx

复制以下内容到 创建好的nginx文件里保存

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/logs/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="/usr/local/nginx/conf/nginx.conf"

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: "

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 2

esac

10.2. 设置/etc/init.d/nginx 执行权限

chmod 777 /etc/init.d/nginx

10.3 设置开机默认启动

chkconfig --add nginx //添加系统服务
chkconfig --level 345 nginx on //设置开机启动,启动级别
chkconfig --list nginx //查看开机启动配置信息

10.4  nginx控制命令

service nginx start   #开启
service nginx stop    #停止
service nginx restart #重启
service nginx reload  #重新加载

---------------------------------------------我是分割线--------------------------------------------------- 

上传路径在/usr/local/nginx/conf 下的nginx.conf里面修改,想让传到哪就指定哪里,没有包就自己建一个

cd /usr/local/nginx/conf
vi nginx.conf

重启nginx

service nginx restart
原文地址:https://www.cnblogs.com/duneF/p/7880352.html