Nginx文件服务器

文件服务器配置

安装Nginx
  • git安装
    yum -y install git

  • gcc 安装
    yum -y install gcc

  • pcre 安装
    yum install pcre pcre-devel

  • openssl安装
    yum install openssl openssl-devel

nginx需要使用 Sticky负载均衡算法,所以需要额外安装Sticky插件,

  • 编译安装Sticky-Nginx
cd ~
mkdir soft
cd soft
wget http://nginx.org/download/nginx-1.12.1.tar.gz
git clone https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng.git
tar -zxvf nginx-1.12.1.tar.gz

cd nginx-1.12.1
# 配置sticky模块 建议填写绝对路径
./configure --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --add-module=../nginx-sticky-module-ng
make
make install
配置Nginx
详细配置解读见: https://blog.youkuaiyun.com/wzw_ice/article/details/89414024

修改/usr/local/nginx/conf/nginx.conf

user  root root;
worker_processes auto;

#error_log  logs/error.log;
error_log  logs/error.log  warn;
error_log  logs/info.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;#文件发送设置

    keepalive_timeout  65;#超时设置

    #gzip  on;

    server {
        listen       8080; #端口修改
        server_name  localhost;

        charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            autoindex on;#自动索引
            autoindex_localtime on;#自动索引时间
            autoindex_exact_size off;#自动索引
            
            #如果设置下面,访问是会直接下载文件
            #idefault_type  'application/octet-stream'; 
            #add_header Content-disposition "attachment";
            
            root    /data/nginxCache/file/;#文件根目录设置
        }
        #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;
        }
      }
}

命令
路径  /usr/local/nginx/sbin/nginx

查看Nginx的版本号:nginx -V

启动Nginx:start nginx

快速停止或关闭Nginx:nginx -s stop

正常停止或关闭Nginx:nginx -s quit

配置文件修改重装载命令:nginx -s reload
测试

curl -Get localhost

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值