文件服务器配置
安装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