安装nginx
./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-pcre
make && make install
配置Nginx
修改/usr/local/nginx/config/nginx.conf
server { client_max_body_size 4G; ##注意80端口的占用问题 listen 80; ## listen for ipv4; this line is default and implied server_name XXX.XXX.XXX; ##你的主机名或者是域名 root /ysdata/upgrade_file/http; location / { autoindex on; ##显示索引 autoindex_exact_size on; ##显示大小 autoindex_localtime on; ##显示时间 } }
测试配置文件是否正确
/usr/sbin/nginx -t
重新加载nginx
service nginx reload
配置密码
搭建文件服务器有时候不想让别人任意访问,想做成一个私有的该怎么办呢,这个时候我们可以用到nginx自带的认证模块。 同样关键的是auth_basic
和 auth_basic_user_file
字段
- auth_basic表示的输入密码时的提示语
- auth_basic_user_file则显示认证时的用户密码文件存放路径
server { client_max_body_size 4G; listen 80; ## listen for ipv4; this line is default and implied server_name xxxx.com; root /home/mini/Sync; location / { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/pass_file; autoindex on; autoindex_exact_size on; autoindex_localtime on; } }
生成密码
htpasswd -c -d /etc/nginx/pass_file test
这样就在/etc/nginx/pass_file
中添加了了一个用户。