安装Nginx

搭建步骤

1:安装FastDFS之前,先安装libevent工具包

yum install gcc-c++

Nginx的安装依赖以下三个包,所以必须在安装Nginx之前安装下面的三个依赖包:

SSL功能需要openssl库,下载地址:http://www.openssl.org/

yum install -y openssl openssl-devel

gzip模块需要zlib库,下载地址:http://www.zlib.net/

yum install -y zlib zlib-devel

rewrite模块需要pcre库,下载地址:http://www.pcre.org/

yum install -y pcre pcre-devel

Nginx的安装包:下载地址为:http://nginx.org/en/download.html

wget -c https://nginx.org/download/nginx-1.12.1.tar.gz

安装软件 安装SSL功能需要的openssl库插件 注意:(这个一步可以先跳过,后面发现需要再来安装, 因为我安装的时候不需要安装这个, 只是为了完整性写上去而已) 注意:安装过程是按照我在linux下设置的文件路径来安装的,

命令如下:

tar -zxvf soft/openssl-SNAP-20160104 cd

cd openssl-SNAP-20160104/

./config

make

sudo make install

安装 pcre-8.39.zip

unzip pcre-8.39.zip

cd  pcre-8.39

 ./configure

make

sudo make install

安装 zlib-1.2.8.tar.xz

tar -zxvf zlib-1.2.8.tar.xz   

cd zlib-1.2.8   

 ./configure   

make    

sudo make install

安装Nginx

cd nginx-1.11.2

./configure

make 

sudo makeinstall,  

安装成功之后,默认会在/usr/local 下创建nginx 目录

[emerg] unknown directive "ngx_fastdfs_module" ngix整合fastdfs启动后报错

cd /home/zpt

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip 

mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1  fastdfs-nginx-module-master

先停掉nginx服务    /usr/local/nginx/sbin/nginx -s stop

进入解压包目录     cd /zpt/nginx-1.12.1/

添加模块     ./configure --add-module=../fastdfs-nginx-module-master/src

重新编译、安装    make && make install

查看Nginx的模块 /usr/local/nginx/sbin/nginx -V 有下面这个就说明添加模块成功

5. 修改目录权限:

chmod a+rwx -R /usr/local/nginx/logs/

chmod a+rwx -R /usr/local/nginx/

6. 检测配置文件是否正确

检测命令: sudo /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.confsyntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test issuccessful

7. 启动nginx

cd /usr/local/nginx/sbin/

./nginx

其它命令 

./nginx -s stop

./nginx -s quit

./nginx -s reload

8. 设置开机启动

vim /etc/rc.local

添加一行:

/usr/local/nginx/sbin/nginx

设置执行权限

chmod 755 rc.local

9. 查看nginx的版本及模块

/usr/local/nginx/sbin/nginx -V

10. 防火墙中打开Nginx端口(默认的 80) 

vim /etc/sysconfig/iptables

添加如下端口行:

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

重启防火墙: service iptables restart

安装Nginx_第1张图片

11. 简单的测试访问文件

vim /usr/local/nginx/conf/nginx.conf

添加如下行,将 /group1/M00 映射到 /ljzsg/fastdfs/file/data

location /group1/M00 {

                       alias /home/zpt/fastdfs/file/data;

                                                }

重启nginx

/usr/local/nginx/sbin/nginx -s reload

安装Nginx_第2张图片

在浏览器访问之前上传的图片、成功

http://file.zpt.com/group1/M00/00/00/wKgz6lnduTeAMdrcAAEoRmXZPp870.jpeg

12. 出错处理:

error: You need a C++ compiler for C++support,看到这句话我们就已经猜到了应该是c++包信息,而linux中没有, 那么首先安装一下这个包信息即可,

安装命令为: yum install -y gcc gcc-c++

当安装完上面的c++包之后,在此运行,发现消息已经显示安装成功了,当基于上面的东西全部安装完成之后,就需要安装Nginx服务了。

 

你可能感兴趣的:(nginx,服务器数据库搭建)