Linux 安装及配置 Nginx + ftp 服务器
Nginx 安装及配置
一、Nginx 简介:
![]() |
Nginx("engine x") 是一款是由俄罗斯的程序设计师 Igor Sysoev 所开发高性能的 Web和 反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。在高连接并发的情况下,Nginx 是 Apache 服务器不错的替代品。是 C 语言编写的,建议在 Linux 运行。 |
二、环境软件版本准备:
系统平台:CentOS release 6.6 (Final) 64位。
Nginx:nginx-1.10.3.tar.gz 下载地址: http://nginx.org/download/nginx-1.10.3.tar.gz
PCRE:pcre-8.35.tar.gz 下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
三、安装编译工具及库文件:
[root@localhost ~]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel |
gcc:安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境。
zlib:zlib 库提供了很多种压缩和解压缩的方式,nginx 使用 zlib 对 http 包的内容进行 gzip。
openssl:OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持http 协议,还支持 https(即在 ssl 协议上传输 http),所以需要在 linux 安装 openssl 库。
PCRE:PCRE(Perl Compatible Regular Expressions) 是一个 Perl 库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre库。
安装 PCRE:
1.解压安装包
[root@localhost moudles]# tar -zxvf pcre-8.35.tar.gz -C ../softwares/ |
2.进入安装目录:
[root@localhost moudles]# cd /opt/softwares/pcre-8.35/ |
3.编译安装:
[root@localhost pcre-8.35]# ./configure |
[root@localhost pcre-8.35]# make && make install |
4.查看 pcre 版本:
[root@localhost pcre-8.35]# pcre-config ––version |
四、Nginx 安装:
1.解压安装包:
[root@localhost moudles]# tar -zxvf nginx-1.10.3.tar.gz -C ../softwares/ |
2.进入安装目录:
[root@localhost moudles]# cd /opt/softwares/nginx-1.10.3/ |
3.编译安装:注意:编译时将临时文件目录指定为 /var/temp/nginx , 需要在/var 目录下递归创建 /temp 和 /nginx 文件夹。
./configure \
--prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi |
[root@localhost nginx-1.10.3]# make && make install |
4.启动报错修复:
[root@localhost nginx-1.10.3]# cd /usr/local/nginx/sbin/ |
[root@localhost sbin]# ./nginx |
从错误看是缺少 lib 包导致的,进一步查看一下:
[root@localhost sbin]# ldd $(which /usr/local/nginx/sbin/nginx) |
从上面的信息可以看出 libpcre.so.1 => not found ,也就是没有找到 libpcre.so.1, 我们进入 /lib64 自己手动链接下。
[root@localhost sbin]# cd /lib64/ |
[root@localhost lib64]# ln -s libpcre.so.0.0.1 libpcre.so.1 |
5.查看 nginx 版本:
[root@localhost lib64]# cd /usr/local/nginx/sbin/ |
6.nginx 常用命令:

- ## 启动 nginx
- [root@localhost sbin]# ./nginx
- ## 停止 nginx
- ## -s都是采用向 Nginx 发送信号的方式
- [root@localhost sbin]# ./nginx -s stop
- [root@localhost sbin]# ./nginx -s quit
- ## Nginx 重载配置
- [root@localhost sbin]# ./nginx -s reload

7.设置防火墙:
CentOS 默认是不开放 80 端口的,这样导致了配置完 Nginx 只能在本机访问(127.0.0.1) 局域网内访问不了 。
① 查看防火墙状态:
[root@localhost sbin]# service iptables status Chain FORWARD (policy ACCEPT) Chain OUTPUT (policy ACCEPT) |
② 开放 80 端口:
[root@localhost sbin]# vim /etc/sysconfig/iptables |
③ 重启防火墙:
[root@localhost sbin]# service iptables restart |
8.nginx启动成功状态:
FTP 安装及配置
一、安装vsftpd组件:
[root@localhost conf]# yum -y install vsftpd |
二、添加一个 FTP 用户:此用户就是用来登陆 FTP 服务器用的。
① 创建用户:
[root@localhost conf]# useradd ftpuser |
创建完用户,可以用这个用户登录,记得用普通登陆,最好不要匿名登陆了。
② 查看是否创建成功:
[root@localhost home]# ls |
③ 为账户添加密码:建议 8 位以上密码
[root@localhost ~]# passwd ftpuser |
三、设置防火墙:
FTP 服务器默认端口为 21, 而 CentOS 默认是不开放 21 端口的。
① 开放 21 端口:
[root@localhost ~]# vim /etc/sysconfig/iptables |
② 重启防火墙:
[root@localhost ~]# service iptables restart |
四、修改 SeLinux:
外网可以访问,但是没有返回目录,也上传不了。
① 查看状态:
[root@localhost ~]# getsebool -a | grep ftp |
注意: 标注两行为 off,代表没有开启外网的访问。
② 开启外网访问:
[root@localhost ~]# setsebool -P allow_ftpd_full_access on |
已经开启。
五、关闭匿名访问:
将 /etc/vsftpd/vsftpd.conf 文件中 anonymous_enable=YES 改成 NO
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf |
六、开启被动模式:
① 设置端口范围:被动模式默认是开启的,但是我们要设置一个端口范围,在 vsftpd.conf 文件结尾加上端口范围, 如:
pasv_min_port=30000 |
② 重启 vsftpd:
[root@localhost vsftpd]# service vsftpd restart |
③ 设置防火墙端口:
[root@localhost vsftpd]# vim /etc/sysconfig/iptables |
④ 重启防火墙:
[root@localhost vsftpd]# service iptables restart |
七、设置开机自启 vsftpd FTP服务:
[root@localhost vsftpd]# chkconfig vsftpd on |
配置 Nginx + FTP 服务器
一、配置Nginx 服务器:
1. 进入nginx 配置文件目录:
[root@localhost vsftpd]# cd /usr/local/nginx/conf/ |
2. 修改配置文件:有两种方式
①方式一:在配置文件server{}中location /{} 修改配置
- 1 #默认请求
- 2 location / {
- 3 root /home/ftpuser/www;#定义服务器的默认网站根目录位置
- 4 index index.html index.php index.htm;#定义首页索引文件的名称
- 5 }
②方式二:在http{}内配置新服务

- 1 server {
- 2 listen 8080;
- 3 server_name localhost;
- 4
- 5 #charset utf-8;
- 6
- 7 #access_log logs/host.access.log main;
- 8
- 9 #默认请求
- 10 location / {
- 11 root /home/ftpuser/www;#定义服务器的默认网站根目录位置
- 12 index index.html index.php index.htm;#定义首页索引文件的名称
- 13 }
- 14 }

部署验证
出现403问题。
解决方案:
1.查看配置文件中路径是否配置成功:
- location / {
- root /home/ftpuser/www;
- index index.html index.htm;
- }
[root@localhost conf]# cd /home/ftpuser/www/ |
两个路径完全匹配,说明路径没有问题。
2.查看路径中是否存在文件:
[root@localhost www]# ls |
存在文件,可以排除是文件问题。
3.排查权限问题:

- [root@localhost conf]# cat nginx.conf
- #user nobody;
- worker_processes 1;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #gzip on;
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root /home/ftpuser/www;
- index index.html index.htm;
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- # HTTPS server
- #
- #server {
- # listen 443 ssl;
- # server_name localhost;
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
- # ssl_session_cache shared:SSL:1m;
- # ssl_session_timeout 5m;
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ssl_prefer_server_ciphers on;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- }

发现用户权限没有开启。我们添加需要的用户。
[root@localhost conf]# vim nginx.conf #user nobody; |
重新加载 nginx 配置:
[root@localhost conf]# cd ../sbin/ |
重新验证
Linux 安装及配置 Nginx + ftp 服务器的更多相关文章
- FTP服务器配置http访问(配置nginx+ftp服务器)
一.搭建nginx服务器 先安装nginx服务器 # yum install nginx -y 启动nginx服务 # systemctl start nginx 浏览器访问:http://192.1 ...
- CentOS7安装及配置vsftpd (FTP服务器)
CentOS7安装及配置vsftpd (FTP服务器) 1.安装vsftpd 1 yum -y install vsftpd 2.设置开机启动 1 systemctl enable vsftpd 3. ...
- CentOS7安装及配置vsftpd (FTP服务器FTP账号创建以及权限设置)
本文章向大家介绍CentOS7安装及配置vsftpd (FTP服务器FTP账号创建以及权限设置),主要包括CentOS7安装及配置vsftpd (FTP服务器FTP账号创建以及权限设置)使用实例.应用 ...
- 烂泥:Windows下安装与配置Nginx web服务器
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 前几篇文章,我们使用nginx都是在linux环境下,今天由于工作的需要.需要在windows环境也使用nginx搭建web服务器. 下面记录下有关ng ...
- centos 5 yum安装与配置vsFTPd FTP服务器
vsftpd作为FTP服务器,在Linux系统中是非常常用的.下面我们介绍如何在centos系统上安装vsftp. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- 通过HTTP服务访问FTP服务器文件(配置nginx+ftp服务器)
1.前提 已安装配置好nginx+ftp服务 2.配置Nginx 服务器 2.1进入nginx 配置文件目录: cd /usr/local/nginx/conf vi nginx.conf 2.2 ...
- centos yum安装与配置vsFTPd FTP服务器(转)
vsftpd作为FTP服务器,在Linux系统中是非常常用的.下面我们介绍如何在centos系统上安装vsftp. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- LNMP1.3一键安装Linux环境,配置Nginx运行ThinkPHP3.2
LNMP1.3一键安装Linux环境,配置Nginx运行ThinkPHP3.2 你是否遇见过:安装LNMP1.3环境后,运行ThinkPHP 3.2,只能打开首页,不能访问控制器,报404错误. 按照 ...
- Linux下安装与配置Nginx
一.准备 Nginx版本:nginx-1.7.7.tar.gz 请自行到官网下载对应的版本. 二.步骤 ♦在Linux新建一个queenLove用户 [root@localhost /]# use ...
随机推荐
- 安装两个JDK后配置环境变量没用?
在实际开发中,由于项目的需要,可能JDK的版本是不同的.比如我们前一个项目所需JDK版本是1.6的,项目完成后,下一个项目JDK版本又是需要1.7的,为了防止由于切换项目我们需要频繁的安装卸载JDK, ...
- vlc源码研究
有位传说中的大神告诉我,我的p2p打洞打不通是因为,sdp描述信息中的地址不对 也就是IN IP4 XXX.XXX.X.XXX这一句 我看到确实是个局域网地址,那么vlc在接收到IN IP4 XXX. ...
- 数据库和 MySQL 简介(真的只是简介)
数据库 si 什么? google.com baidu.com 数据库服务器,数据管理系统,数据库,表与记录的关系
- JavaScript 之DOM&BOM
重点来了 : BOM对象 window对象 : 所有浏览器都支持window对象. 概念上讲 : 一个html文档对应一个window对象. 功能上讲 : 控制浏览器窗口的. 使用上讲 : windo ...
- js解析xml浏览器兼容性处理
/****************************************************************************** 说明:xml解析类 ********** ...
- IIS Express总结
IIS Express可以说是.NET web开发者必用的服务器,日日夜夜都和它打交道.一直以来,除了遇到什么点什么问题,很少会去关注过它. 今天看到以前转载的一篇博客,就再次温故下,主要包含IIS ...
- 用Python让单片机“行动”起来——MicroPython实战入门篇
MicroPython以微控制器作为目标,从而使得Python可以用来控制硬件.说到MicroPython,也许有人会感到陌生.而说到和它密切相关的Python,是否会恍然大悟呢?Python属于解释 ...
- angular4.0运行在微信端的坑坑洼洼
最近的一个项目,我用ng4操刀,踩了超多的坑: 坑1:项目build后,刷新后404错误: 解决方案:<angular4.0项目build发布后,刷新页面报错404> 坑2:微信分享: 运 ...
- SQL列中含有换行符的查找和替换方法
最近在获取数据时,发现程序读取的字段中含有\r\n字符,检查数据库表中的数据,发现是varchar字符串中包含了换行符.导入数据导致了这一情况出现. 回车换行 不同系统的行结尾符号并不同,如下: li ...
- Python学习九:列表生成式
列表生成式,是Python内置的一种极其强大的生成list的表达式. 如果要生成一个list [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9] 可以用 range(1 , 10) ...