脚本/编译安装nginx1.11.10

发布于:2025-02-10 ⋅ 阅读:(79) ⋅ 点赞:(0)

1、通过脚本安装nginx1.11.10

  • 在保证yum源正常(国内源)的情况下,这个脚本是可以正常安装的
  • –with-pcre=/usr/src/pcre-8.12/ # 如果自带的pcre无效就使用这个自定义pcre的路径(pcre安装在第3步骤)
#!/bin/bash

#安装nginx所需依赖包
yum -y install pcre*  pcre-devel  gcc-c++  openssl openssl-devel zlib*

#创建nginx运行用户
useradd www -s /sbin/nologin

#nginx源码包存放路径
source_dir='/soft'
mkdir -p $source_dir

#nginx安装路径
nginx_dir='/alidata/server/nginx-1.11.10'
mkdir -p $nginx_dir

#下载并安装nginx
cd $source_dir && wget http://nginx.org/download/nginx-1.11.10.tar.gz && tar zxvf nginx-1.11.10.tar.gz && cd nginx-1.11.10

./configure \
--prefix=$nginx_dir \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-pcre \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log
make && make install

#更改nginx所有主和所有组
chown -R www.www /alidata/server/nginx-1.11.10

#修改nginx运行用户
sed -i 's/#user  nobody/user  www/g' $nginx_dir/conf/nginx.conf

#添加nginx启动脚本
cat >/etc/init.d/nginxd<<EOF
#!/bin/bash
case \$1 in
    start)
        $nginx_dir/sbin/nginx
    ;;

    stop)
        $nginx_dir/sbin/nginx -s stop >/dev/null 2>&1
    ;;

    restart)
        $nginx_dir/sbin/nginx -s stop >/dev/null 2>&1
        $nginx_dir/sbin/nginx
    ;;

    reload)
        $nginx_dir/sbin/nginx -s reload
    ;;
    	test)
		/alidata/server/nginx-1.11.10/sbin/nginx -t
    ;;

    status)
		netstat -npult|grep nginx|grep -v "grep"
    ;;

    *)
        echo "start|stop|restart|reload"
    ;;
esac
EOF

#启动nginx
chmod +x /etc/init.d/nginxd
echo "/etc/init.d/nginxd start" >> /etc/rc.local
/etc/init.d/nginxd start
netstat -nptul|grep nginx

2、配置nginx虚拟主机

# 先创建存放虚拟主机的目录
# mkdir -p /alidata/nginx/conf.d/

# 映射虚拟主机目录
# vi /etc/nginx.conf
http {
	include /alidata/nginx/conf.d/*.conf;   
    # include /alidate/nginx/conf/*.conf;   #不要直接把虚拟主机映射到nginx的主配置目录下面
}

# 创建站点目录
# mkdir -p /alidata/www/; echo "nginx 1.1.11" > index.html

# 配置虚拟主机
# vi /alidata/nginx/conf.d/vhost.conf         
################## www.abc.org ##############
server {
        listen        80;
        server_name  www.abc.org; 
        location / {
            # root   html;           # 默认站点目录(/alidata/server/nginx-1.11.10/html/)
            root   /alidata/www/www_xialan_com;     # 自定义站点目录
            index  index.php  index.html index.htm;
	}

        # 禁止访问.svn|.git|.cvs结尾的文件
	location ~ .*.(svn|Git|cvs) {
        deny all;
        }
}

3、安装pcre-8.12
pcre 安装到 /usr/local/ 解包到/usr/src/

# tar zxvf pcre-8.12.tar.gz -C /usr/src/     # 源码包解压到这里
# cd /usr/src/pcre-8.12/
# ./configure --prefix=/usr/local/             # 安装到这里
make  &&  make install

注意nginx中要指定pcre的源码包路径
./configure --with-pcre=/usr/src/pcre-8.12/

网站公告

今日签到

点亮在社区的每一天
去签到