時間:2023-07-10 21:36:02 | 來源:網(wǎng)站運營
時間:2023-07-10 21:36:02 來源:網(wǎng)站運營
Linux服務器上建站指南:當年騰訊云做校園優(yōu)惠的時候入手了每月一塊錢的服務器,在Apache上搭了WordPress用來寫博客。然而由于疏于維護,網(wǎng)站經(jīng)常遭到攻擊,動不動就死機。最近干脆重裝了系統(tǒng),打算從頭建立一個注重安全的服務器。# Allow anonymous FTP? (Beware - allowed by default if you comment this out).anonymous_enable=YES## Uncomment this to allow local users to log in.# When SELinux is enforcing check for SE bool ftp_home_dirlocal_enable=YES## Uncomment this to enable any form of FTP write command.write_enable=YES## below is some useful settingspasv_enable=YESpasv_max_port=65410pasv_min_port=65400
然后安全組選擇開放TCP:20,21,65400-65410入站,ftp就搭建完成了!輸入命令systemctl restart vsftpd 啟動!useradd www -m -r
網(wǎng)站的主要文件將存放于/home/www目錄下,該賬號不能登錄Bash,也沒有管理員權(quán)限,這樣即使網(wǎng)站被攻破了也不影響服務器的其它服務。worker_processes 1; #nginx worker 數(shù)量error_log logs/error.log; #指定錯誤日志文件路徑events { worker_connections 1024;}http { server { #監(jiān)聽端口,若你的80端口已經(jīng)被占用,則需要修改 listen 80; # processes requests ending with the slash character # using an index file causes an internal redirect # a “/” request will actually be processed # in the second location as “/index.html”. location = / { root static; index index.html; } location ~ /.(html|txt|ico)$ { content_by_lua_block { local file, err = io.open(ngx.config.prefix() .. "static" .. ngx.var.uri, "r") if not file then ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE) end ngx.print(file:read("*a")) file:close() } } location / { content_by_lua_block { ngx.exit(ngx.HTTP_BAD_REQUEST) } } }}
事實上,本身Nginx就提供了很好的靜態(tài)文件的處理功能。但我們這里用content_by_lua_block模塊代替Nginx輸出響應體則可以做到更加靈活地處理請求。例如當找不到目標文件時,Nginx默認會返回404并在日志中記錄該錯誤,我們在這里則可以有更多的處理。export PATH=/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:$PATH
以及允許普通用戶啟動Nginx時使用1024以下的端口:setcap cap_net_bind_service+eip /usr/local/openresty/nginx/sbin/nginx
重啟之后就可以啟動Nginx服務了:nginx -p ~/openresty-test
如果修改了配置文件,可以執(zhí)行重裝載命令使用新的配置:nginx -p ~/openresty-test -s reload
使用ps命令可以查看Nginx進程:ps -ef | grep nginx
使用kill結(jié)束Nginx進程:kill -QUIT $( cat ~/openresty-test/logs/nginx.pid )
關鍵詞:指南,服務
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。