当前位置: 首页 > Linux

键盘侠Linux干货-使用Nginx创建私有网盘

时间:2023-04-06 18:37:03 Linux

前言使用Nginx创建私有网盘安装Nginx添加Nginx官方源码cat</etc/yum.repos.d/nginx.repo[nginx-stable]name=nginx稳定repobaseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/gpgcheck=1enabled=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true[nginx-mainline]name=nginxmainlinerepobaseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/gpgcheck=1enabled=0gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=trueEOFEPELsource中的nginx.service因为KILL参数的问题,启动后无法停止,不推荐使用。安装Nginxyuminstall-ynginx备份Nginx配置文件echoy|cp/etc/nginx/nginx.conf/etc/nginx/nginx.conf.default修改nginx.confcat</etc/nginx/nginx.conf#For有关配置的更多信息,请参阅:#*官方英文文档:http://nginx.org/en/docs/#*官方俄文文档:http://nginx.org/ru/docs/usernginx;worker_processesauto;error_log/var/log/nginx/error.logwarn;pid/var/run/nginx.pid;worker_rlimit_nofile65535;events{worker_connections65535;}http{include/etc/nginx/mime.types;default_type应用程序/八位字节流;log_formatmain'\$host\$server_port\$remote_addr-\$remote_user[\$time_local]"\$request"''\$status\$request_time\$body_bytes_sent"\$http_referer"''"\$http_user_agent""\$http_x_forwarded_for"';access_log/var/log/nginx/access.logmain;发送文件;tcp_nopush上;TCP_节点依赖;keepalive_timeout65;types_hash_max_size2048;server_names_hash_bucket_size128;server_name_in_redirect关闭;client_header_buffer_size32k;large_client_header_buffers432k;client_header_timeout3m;client_body_timeout3m;client_max_body_size50m;client_body_buffer_size256k;发送超时3m;gzip上;gzip_min_length1k;gzip_buffers416k;gzip_http_version1.0;gzip_comp_level2;gzip_types文本/纯应??用程序/x-javascript文本/css应用程序/xml;gzip_vary开启;proxy_redirect关闭;proxy_set_header主机\$主机;proxy_set_headerX-Real-IP\$remote_addr;proxy_set_headerREMOTE-HOST\$remote_addr;proxy_set_headerX-Forwarded-For\$proxy_add_x_forwarded_for;proxy_connect_timeout60;代理发送超时60;proxy_read_timeout60;proxy_buffer_size256k;proxy_buffers4256k;proxy_busy_buffers_size256k;临xy_temp_file_write_size256k;proxy_next_upstreamerrortimeoutinvalid_headerhttp_500http_503http_404;proxy_max_temp_file_size128m;#让代理服务端不要主动关闭客户端的连接,协助处理499返回代码问题proxy_ignore_client_aborton;fastcgi_buffer_size64k;fastcgi_buffers464k;fastcgi_busy_buffers_size128k;indexindex.htmlindex.htmindex.phpdefault.htmldefault.htmdefault.php;#Loadmodularconfigurationfilesfromthe/etc/nginx/conf.ddirectory.#Seehttp://nginx.org/en/docs/ngx_core_module.html#include#formoreinformation.include/etc/nginx/conf.d/*.conf;}EOFincreasesthedefaultHostmkdir/etc/nginx/conf.dcat</etc/nginx/conf.d/default.confserver{listen80default_server;listen[::]:80default_server;server_name_;root/usr/share/nginx/html;#Loadconfigurationfilesforthedefaultserverblock.include/etc/nginx/default.d/*.conf;location/{}error_page404/404.html;location=/40x.html{}error_page500502503504/50x.html;location=/50x.html{}}EOF启动Nginxsystemctlstartnginx增加开机启动systemctlenablenginx查看Nginx状态#systemctlstatusnginx●nginx.service-nginx-高性能web服务器Loaded:loaded(/usr/lib/systemd/system/nginx.service;已启用;供应商预设:禁用)活动:活动(运行)自美国东部时间2020年5月25日星期一05:50:22起;7s前文档:http://nginx.org/en/docs/CGroup:/system.slice/nginx.service├─1853nginx:masterprocess/usr/sbin/nginx-c/etc/nginx/nginx.conf└─1854nginx:workerprocessMay2505:50:22mysql1systemd[1]:启动nginx-高性能Web服务器...May2505:50:22mysql1systemd[1]:无法打开PID文件/var/启动后运行/nginx.pid(yet?):NosuchfileordirectoryMay2505:50:22mysql1systemd[1]:Startednginx-highperformancewebserver.#ss-antpl|grepnginxLISTEN0128*:80*:*用户:(("nginx",pid=1854,fd=6),("nginx",pid=1853,fd=6))LISTEN0128[::]:80[::]:*用户:(("nginx",pid=1854,fd=7),("nginx",pid=1853,fd=7))搭建私有网盘,安装密码工具yuminstall-yhttpd-tools使用密码生成密码文件的工具htpasswd-c/data/.htpasswdgeek(用户名)添加网盘配置文件mkdir-p/data/softwarecat</etc/nginx/conf.d/download.confserver{listen9090默认服务器;服务器名称_;根/数据/软件;#开启HTTP密码认证auth_basic"管理员密码";auth_basic_user_file/data/.htpasswd;包括/etc/nginx/default.d/*.conf;位置/{自动索引开启;autoindex_localtime开启;#设置文件大小显示单位autoindex_exact_sizeoff;}}EOFReloadNginx使配置生效nginx-t&&nginx-sreload添加内容到网盘添加QQ安装包cd/data/software/wgethttps://down.qq.com/qqweb/PCQQ/PCQQ_EXE/PCQQ2020.exe访问网盘http://服务器IP地址:9090输入刚才配置的用户名和密码即可访问。注意事项网盘下载文件保存位置:/data/software/如果是阿里云ECS,需要添加安全组规则,9090端口放行写在最后,如果文档对你有帮助,请点个赞离开。您的点击是我最大的动力。我是键盘侠更多键盘侠Linux系列教程:更多Linux干货教程链接地址请扫一扫:(回复干货)