搭建ftp和nginx共享服务器

1.安装配置ftp后新建ftp用户账号

[root@localhost ~]# useradd ftpnginx -s /sbin/nologin
[root@localhost ~]# passwd ftpnginx

该账户路径默认指向/home/ftpnginx目录
/sbin/nologin是不允许系统login,可以使用其他ftp等服务

【特别注意】
ftp会根据/etc/shells这个文件来判断一个用户是否是有效用户,那些shell不在/etc/shells里的用户会被阻止登陆.所以如果ftp用户的登录shell为/sbin/nologin 则添加到/etc/shells文件里面
[root@localhost etc]# vim /etc/shells

/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/sbin/nologin

2.创建文件存储路径

[root@localhost ~]# mkdir /home/ftpnginx/www/images

3.ftp登陆并拷贝图片至目录下

a.查看IP
[root@localhost ~]# ifconfig
获取IP为192.168.139.129

b.浏览器输入ftp://192.168.139.129/登陆
输入用户ftpnginx及其密码登陆

c.copy 图片到目录/www/images下
在这里插入图片描述

4.nginx安装包下载并解压

a.进入安装包管理目录
[root@localhost ~]# cd /usr/local/src

b.下载Nginx的源码包
[root@localhost src]# wget http://nginx.org/download/nginx-1.9.3.tar.gz

c.下载正则表达式库
[root@localhost src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

d.解压
[root@localhost src]# tar zxf nginx-1.9.3.tar.gz
[root@localhost src]# tar zxf pcre-8.39.tar.gz

5.安装gcc环境

[root@localhost src]# yum install -y wget gcc gcc-c++ make openssl-devel

6. 进入解压目录,配置环境变量

[root@localhost src]# cd /usr/local/src/nginx-1.9.3
[root@localhost nginx-1.9.3]# ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.39

7. 编译安装

[root@localhost nginx-1.9.3]# make install

8. 启动 nginx

[root@localhost nginx-1.9.3]# /usr/local/nginx/nginx

9. 搭建 nginx 文件服务器

a.在/usr/local/nginx/html下创建一个images文件夹用来做映射
[root@localhost nginx-1.9.3]# mkdir -p /usr/local/nginx/html/images

b.编辑nginx.conf文件做ftp与nginx服务映射
[root@localhost nginx-1.9.3]#cd /usr/local/nginx
[root@localhost nginx]# vim nginx.conf

//添加用户
在这里插入图片描述

//添加映射连接
在这里插入图片描述

c.重新载入配置文件
[root@localhost nginx]# ./nginx -s reload

10. 授权文件夹

[root@localhost nginx]# chmod 777 -R /home/ftpnginx

11.浏览器输入地址登陆

http://192.168.139.129/images/

在这里插入图片描述

12.若无法连接,需配置防火墙

12.1 iptables方式

a.验证是防火墙原因导致不能登录
[root@localhost nginx]# service iptables stop
若关闭防火墙后可以登陆,则需要对防火墙进行配置

b.查看nginx所使用的侦听端口:
[root@localhost nginx]# vim nginx.conf在这里插入图片描述
c.添加防火墙80端口
[root@localhost ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@localhost ~]# service iptables restart

d.再进行登陆发现成功。

12.2 firewalld方式

a.firewalld方式只需以下指令
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@localhost ~]# firewall-cmd --reload

b.再进行登陆发现成功。

13.设置开机启动nginx

a.在/etc/init.d/目录下创建nginx文件
[root@localhost ~]# vim /etc/init.d/nginx
添加:

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/nginx
nginx_config=/usr/local/nginx/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}

b.保存脚本文件后设置文件的执行权限:
[root@localhost ~]# chmod a+x /etc/init.d/nginx

c.此时就可以通过该脚本对nginx服务进行管理了:
[root@localhost ~]# /etc/init.d/nginx start
[root@localhost ~]# /etc/init.d/nginx stop

d.将nginx服务加入chkconfig管理列表:
[root@localhost ~]# chkconfig --add /etc/init.d/nginx

e.此时就可以通过service对nginx服务进行管理了:
[root@localhost ~]# service nginx start
[root@localhost ~]# service nginx stop

f.设置开机启动nginx
[root@localhost ~]# chkconfig nginx on

g.查看nginx的开机状态
[root@localhost ~]# reboot
[root@localhost ~]# ps -ef|grep nginx
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值