一,下载安装ftp服务器(vsftpd)
1. 使用命令安装vsftpd服务器:
[root@localhost /]# yum -y install vsftpd
2.开启20,21端口
vi /etc/sysconfig/iptables
加上
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT
3.将iptables-config 的 IPTABLES_MODULES=
"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp"
不设置会读取目录失败。
vi /etc/sysconfig/iptables.conf
保存,重启防火墙·
service iptables restart
4. 将selinux设置为宽容模式(permissive)。不设置报错500 OOPS: cannot change directory:/home/*******
vi /etc/sysconfig/selinux
5. 添加一个用户:
[root@localhost /]# adduser ftpuser
[root@localhost /]# passwd ftpuser
输入ftpuser的登录密码 。这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser。
二,下载安装nginx服务器
A.环境准备
nginx是C语言开发,建议在linux上运行,本教程使用Centos7作为安装环境。
1. gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:
yum install gcc-c++
2. PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
3. zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
4. openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。 nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
B.下载编译安装
1. 下载:
wget http://nginx.org/download/nginx-1.8.0.tar.gz
2. 解压
tar -zxf nginx-1.8.0.tar.gz
3. 进入nginx解压过的文件夹
cd nginx-1.8.0
使用命令:
./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
4.编译安装
make&make install
安装目录为:/usr/local/
5.开启80端口
vi /etc/sysconfig/iptables
加入
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启防火墙
6.启动 nginx
cd /usr/local/nginx/sbin
./nginx
停止nginx
./nginx -s stop
虚拟机内部访问 地址为虚拟机的ip地址 port:80
安装成功。
三,ftp服务器与nginx服务器结合。
[root@localhost /]# vi /usr/local/nginx/conf/nginx.conf
更改nginx.conf的配置。以下都是在/usr/local/nginx/conf/nginx.conf 中配置两个地方。
添加 user root;
user root;
#user nobody;
将location 的 root 改为/home/ftpuser
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/ftpuser;
index index.html index.htm;
}
此时使用http请求会出现以下错误。
经过查资料发现刚刚配置的nginx.conf,root /home/ftpuser。ftpuser文件夹下面没有 index.php和index.html。只需进入到ftpuser文件夹下面,新建一个文件命名为 index.php或者index.html。即可解决。