Linux下文件服务器配置

21 篇文章 1 订阅

1. 设置nginx开机自动启动

这里使用的是编写shell脚本的方式来处理:

创建一个shell脚本nginx:

cd /etc/init.d
[root@winy init.d]# touch nginx
vi nginx 

打开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/sbin/nginx
nginx_config=/usr/local/nginx/conf/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
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

:wq  保存并退出


2. 设置文件的访问权限

chmod a+x /etc/init.d/nginx

(a+x ==> all user can execute  所有用户可执行)

这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx

比如以下命令:
[root@winy init.d]# /etc/init.d/nginx status   --nginx运行状态
[root@winy init.d]# /etc/init.d/nginx restart  --重启
[root@winy init.d]# /etc/init.d/nginx start    --启动
[root@winy init.d]# /etc/init.d/nginx stop     --停止


3. 加入到rc.local文中

vi /etc/rc.local

加入一行  /etc/init.d/nginx start    保存并退出,下次重启会生效。


4.  配置文件服务器

cd /usr/local/nginx/conf
vi nginx.conf
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;

修改nginx.conf文件,上面标红的地方即可!


5. 测试

根据上面的nginx.conf配置文件可知,我的ftp目录为/home/ftpuser/www

那么我在www目录下面新建一个存放图片的目录images,

通过FileZilla 往images文件夹下添加一张图片hello.jpg,

那么在win7下通过浏览器url访问即可浏览到图片!!!!!

http://服务器ip/images/hello.jpg


注意点:

1. 防火墙设置

2. 之前有修改过nginx.conf文件,但是改坏了,而又没有手动备份,这时可以复制一份系统备份的文件

cp nginx.conf.default nginx.conf    ,然后再修改里面的标红部分!

3. win7访问的时候提示403 forbidden

调查方法一:

修改nginx.conf第一行user为root,默认是被注释掉的,放开

[root@winy conf]# vi nginx.conf
user  root;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


调查方法二:

修改ftp服务器文件夹的访问权限:

chmod 777 your_images_folder

对于我来说的话,这里的your_images_folder对应的我得ftp文件夹  /home/ftpuser/www




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值