Linux-CentOS6.9安装Nginx-1.12.2

Linux-CentOS6.9安装Nginx-1.12.2

sudo -s
创建www用户和组
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

创建虚拟主机目录 可建多个

mkdir -p /data0/vhosts/www
chmod +w /data0/vhosts/www
chown -R www:www /data0/vhosts/www

mkdir -p /data0/vhosts/localhost
chmod +w /data0/vhosts/localhost
chown -R www:www /data0/vhosts/localhost

创建Nginx日志目录

mkdir -p /data0/logs
chmod +w /data0/logs
chown -R www:www /data0/logs
安装依赖
yum install gcc gcc-c++ make libtool autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

安装依赖 Nginx 的 Rewrite 功能需要 PCRE

cd /data0/software
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar zxvf pcre-8.38.tar.gz
cd pcre-8.38/
./configure
make && make install

pcre-config --version
安装Nginx-1.12.2
cd /data0/software
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

安装成功 查看版本

/usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.12.2

Nginx启动

# 启动Nginx
/usr/local/nginx/sbin/nginx

# 检查配置是否正确
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

# 平滑重启
/usr/local/nginx/sbin/nginx -s reload

检查nginx进程

ps -ef |grep nginx
搭建Nginx+php-fpm+PHP5或Nginx+php-fpm+PHP7或Nginx+uWSGI+Python开发环境

Linux-CentOS6.9安装PHP5.6
Linux-CentOS6.9安装PHP7.2
Linux-CentOS6.9搭建Nginx+uWSGI+Python3+Django开发环境

配置开机启动Nginx

vi /etc/rc.local

在末尾增加以下内容

ulimit -SHn 65535
/usr/local/nginx/sbin/nginx

修改防火墙配置 增加一行 放22下面

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙

service iptables restart
安装常见问题及解决方法

提示
./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决

创建软连接

对于/lib/* 32位系统
查看lib库

ls /lib/ |grep pcre

libpcre.so.0
libpcre.so.0.0.1

添加软连接

ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1

也有可能 pcre lib文件在目录 /usr/local/lib/

对于/lib64/* 64位系统
查看lib库

ls /lib64/ |grep pcre

libpcre.so.0
libpcre.so.0.0.1

添加软连接

ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1

也有可能 pcre lib文件在目录 /usr/local/lib64/

/usr/local/nginx/sbin/nginx -t

提示
nginx: [emerg] “log_format” directive is not allowed here in /usr/local/nginx/conf/nginx.conf:84

解决
将server段里的 log_format 放server段的前面即可

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页