1、指定在每天凌晨4:00將該時間點之前的系統日志信息(/var/log/messages )備份到目錄下/backup,備份后日志文件名顯示格式logfileYY-MM-DD-HH-MM
2、配置ssh免密登陸:客戶端主機通過redhat用戶基于秘鑰驗證方式進行遠程連接服務器的root用戶。
3、
nginx基本配置
?
? [root@localhost ~]# dnf install nginx -y
? ? [root@localhost ~]# nginx -v
? ? [root@localhost ~]# nginx -V
? ? [root@localhost ~]# rpm -ql nginx
? ? [root@localhost httpd]# tree /etc/nginx
? ? [root@localhost ~]# tree /etc/nginx/
? ? /etc/nginx/
? ? ├── conf.d ? ? #子配置文件目錄
? ? ├── default.d ?
? ? ├── fastcgi.conf
? ? ├── fastcgi.conf.default
? ? ├── fastcgi_params ?#用以翻譯nginx的變量供php識別
? ? ├── fastcgi_params.default
? ? ├── koi-utf
? ? ├── koi-win
? ? ├── mime.types ? #用以配置支持的媒體文件類型
? ? ├── mime.types.default
? ? ├── nginx.conf ? ?#主配置文件
? ? ├── nginx.conf.default
? ? ├── scgi_params
? ? ├── scgi_params.default
? ? ├── uwsgi_params ?#用以配置nginx的變量供python識別
? ? ├── uwsgi_params.default
? ? └── win-utf
? ? [root@localhost ~]# tree /usr/share/nginx/html/ ?#默認的nginx網站根目錄
? ? [root@localhost ~]# tree /var/log/nginx/ ?#nginx的日志文件所在目錄
? ??
? ??
? ? #nginx服務主配置文件nginx.conf的結構
? ? [root@localhost nginx]# grep ? ^[^#] nginx.conf
? ? =========全局配置(無{}標志)=======================
? ? user nginx; ? ? ? #進程所屬用戶
? ? worker_processes auto; ?#worker數量
? ? error_log /var/log/nginx/error.log; ?#錯誤日志存放路徑
? ? pid /run/nginx.pid; ?#pid文件路徑
? ? include /usr/share/nginx/modules/*.conf; ?#include導入的功能模塊配置文件
? ? =========全局配置(無{}標志)=======================
? ??
? ? ==========性能配置(有{}標志)=================
? ? events {
? ? ? ? worker_connections 1024; ?#TCP連接數
? ? }
? ? ==========性能配置(有{}標志)=================
? ??
? ? =========http模塊配置(有{}標志)==================
? ? http { ? #http區塊開始
? ? ? ? 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 ?/var/log/nginx/access.log ?main; ?#訪問日志路徑
? ? ? ? sendfile ? ? ? ? ? ?on; ? #開啟高效文件傳輸模式
? ? ? ? tcp_nopush ? ? ? ? ?on; ? #性能優化參數
? ? ? ? tcp_nodelay ? ? ? ? on; ? #性能優化參數
? ? ? ? keepalive_timeout ? 65; ? #持久連接時間或超時時間
? ? ? ? types_hash_max_size 4096; ?#性能優化參數
? ? ? ? include ? ? ? ? ? ? /etc/nginx/mime.types; ?#可解析的靜態資源類型
? ? ? ? default_type ? ? ? ?application/octet-stream; ?
? ? ? ? # Load modular configuration files from the /etc/nginx/conf.d directory.
? ? ? ? # See http://nginx.org/en/docs/ngx_core_module.html#include
? ? ? ? # for more information.
? ? ? ? include /etc/nginx/conf.d/*.conf; ?#子配置文件存放路徑
? ? ? ? server { ?#server區塊開始
? ? ? ? ? ? listen ? ? ? 80; ? #監聽端口
? ? ? ? ? ? listen ? ? ? [::]:80;
? ? ? ? ? ? server_name ?_; ? ?#服務器的名字
? ? ? ? ? ? root ? ? ? ? /usr/share/nginx/html; ?#主頁存放路徑
? ? ? ? ? ? # Load configuration files for the default server block.
? ? ? ? ? ? include /etc/nginx/default.d/*.conf; ?#子配置文件存放路徑
? ? ? ? ? ? error_page 404 /404.html; ?#404錯誤返回的頁面
? ? ? ? ? ? ? ? location = /40x.html { ?#使用location定義用戶請求的uri
? ? ? ? ? ? }
? ? ? ? ? ? error_page 500 502 503 504 /50x.html; #500、502、503、504返回的頁面
? ? ? ? ? ? ? ? location = /50x.html {
? ? ? ? ? ? }
? ? ? ? } ?#server區塊結束
? ? } ? #http區塊結束
? ? =========http模塊配置(有{}標志)==================
? ? [root@localhost ~]#systemctl disable firewalld --now
? ? [root@localhost ~]# systemctl restart nginx
? ? #測試可以使用curl命令訪問web服務器或者使用瀏覽器訪問
? ? [root@localhost ~]# curl -I ?localhost
? ? HTTP/1.1 200 OK
? ? Server: nginx/1.21.5
? ? Date: Fri, 17 Nov 2023 08:40:28 GMT
? ? Content-Type: text/html
? ? Content-Length: 3510
? ? Last-Modified: Mon, 23 Oct 2023 15:48:29 GMT
? ? Connection: keep-alive
? ? ETag: "653695cd-db6"
? ? Accept-Ranges: bytes
作業
構建靜態網站
echo "hello world" > /usr/share/nginx/html/index.html
訪問
curl 192.168.59.132
設置基于地址的網頁訪問
創建根目錄
mkdir -pv /www/ip/100
mkdir -pv /www/ip/200
構建網站
echo this is 100 > /www/ip/100/index.html
echo this is 200 > /www/ip/200/index.html
設置selinux
?setenforce 0
#設置SELinux為permissive模式,這樣可以避免無法看到網頁頁面內容的問題
創建并編寫配置文件
[root@localhost ~]# vim /etc/nginx/conf.d/test_ip.conf
server {
? ? ? ? listen 192.168.59.100:80;
? ? ? ? root /www/ip/100;
? ? ? ? location / {
? ? ? ? }
}
server {
? ? ? ? listen 192.168.59.200:80;
? ? ? ? root /www/ip/200;
? ? ? ? location / {
? ? ? ? }
}
效果
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# curl 192.168.59.100
this is 100
[root@localhost ~]# curl 192.168.59.200
this is 200
設置基于端口的網站訪問
創建根目錄
mkdir -pv /www/port/80
mkdir -pv /www/port/8000
創建并編寫配置文件
[root@localhost ~]# cat ?/etc/nginx/conf.d/test_port.conf
server {
? ? ? ? listen 192.168.59.132:80;
? ? ? ? root /www/port/80;
? ? ? ? location / {
? ? ? ? }
}
server {
? ? ? ? listen 192.168.59.132:10000;
? ? ? ? root /www/port/10000;
? ? ? ? location / {
? ? ? ? }
}
?
?