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 ...
随机推荐
- ubuntu 安装 pythonenv
This will get you going with the latest version of pyenv and make it easy to fork and contribute any ...
- rsync服务器的搭建
Rsync(remote synchronize)是一个远程数据同步工具,简要的概括就是主机于主机之间的文件目录数据的一个同步.下面就是rsync服务器的搭建过程. 系统环境 平台:Centos ...
- 微信小程序生成带参数的二维码 小程序二维码
我是用php写的 先按照要求生成accesstoken $tokenUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=clien ...
- robotframework的学习笔记(十三)------Robot Framework常用库简介
标准库 Robot Framework可以直接导入使用的库,包括: Builtin:包含经常需要的关键字.自动导入无需import,因此总是可用的 Dialogs:提供了暂停测试执行和从用户的输入方式 ...
- 单独mybatis得使用
今天同学说要学习mybatis后来他写了个程序让我看看,我看了一下发现包引错了,他写的是单独的mybatis,引入的却是spring-mybatis,所以会报错. 今天我记录一下单独mybatis的使 ...
- (五):C++分布式实时应用框架——微服务架构的演进
C++分布式实时应用框架--微服务架构的演进 上一篇:(四):C++分布式实时应用框架--状态中心模块 版权声明:本文版权及所用技术归属smartguys团队所有,对于抄袭,非经同意转载等行为保留法律 ...
- BASIC-3 字母图形 循环 字符串
基础练习 字母图形 时间限制:1.0s 内存限制:256.0MB 问题描述 利用字母可以组成一些美丽的图形,下面给出了一个例子: ABCDEFG BABCDEF CBABCD ...
- JQuery 网页瞄点
$("html,body").animate({ scrollTop: $("#Content1").offset().top }, 3000); 代码说明:h ...
- IE常见bug及其修复方法
一.双边距浮动的bug 1.1一段无错的代码把一个居左浮动(float:left)的元素放置进一个容器盒(box) 2.1在浮动元素上使用了左边界(margin-left)来令它和容器的左边产 ...
- .NET使用Office Open XML导出超大数量数据到 Excel
我相信很多人在做项目的都碰到过Excel数据导出的需求,我从最开始使用最原始的HTML拼接(将需要导出的数据拼接成TABLE标签)到后来happy的使用开源的NPOI, EPPlus等开源组件导出EX ...