網站部署
阿新 • • 發佈:2021-08-08
網站部署
部署nginx網站
# 1.新增nginx虛擬主機配置 [Sun Jul 18 23:45:01 root@web02 ~] # vi /etc/nginx/conf.d/game.wk.com.conf server{ # 監聽80埠 listen 80; # 指定訪問的域名 server_name game.wk.com; # 配置URL location / { # 站點目錄 root /code/h5_games; # 指定主頁面 index index.html; } } # 2.建立站點目錄 [Mon Jul 19 00:00:27 root@web02 ~] # mkdir /code # 3.修改站點目錄許可權 [Mon Jul 19 00:04:45 root@web02 ~] # chown nginx.nginx /code/ # 4.部署程式碼 [Mon Jul 19 00:05:38 root@web02 ~] # cd /code/ [Mon Jul 19 00:08:58 root@web02 /code] # wget http://test.driverzeng.com/Nginx_Code/h5_games.zip # 5.解壓程式碼 [Mon Jul 19 00:09:20 root@web02 /code] # unzip h5_games.zip # 6.重新載入nginx的配置檔案 [Mon Jul 19 00:12:10 root@web02 /code] # systemctl reload nginx # 7.本地域名解析 windows開啟:C:\Windows\System32\drivers\etc\hosts檔案 10.0.0.8 game.wk.com # 8.開啟瀏覽器:http://game.wk.com
Nginx的虛擬主機
基於IP方式
基於埠方式
基於域名方式
nginx日誌管理
log_format main '$remote_addr - $remote_user [$time_local] "$request" $request_time ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; $remote_addr # 記錄客戶端IP地址 $remote_user # 記錄客戶端使用者名稱 $time_local # 記錄通用的本地時間 $time_iso8601 # 記錄ISO8601標準格式下的本地時間 $request # 記錄請求的方法以及請求的http協議 $status # 記錄請求狀態碼(用於定位錯誤資訊) $body_bytes_sent # 傳送給客戶端的資源位元組數,不包括響應頭的大小 $bytes_sent # 傳送給客戶端的總位元組數 $msec # 日誌寫入時間。單位為秒,精度是毫秒。 $http_referer # 記錄從哪個頁面連結訪問過來的 $http_user_agent # 記錄客戶端瀏覽器相關資訊 $http_x_forwarded_for #記錄客戶端IP地址 $request_length # 請求的長度(包括請求行, 請求頭和請求正文)。 $request_time # 請求花費的時間,單位為秒,精度毫秒 # 注:如果Nginx位於負載均衡器,nginx反向代理之後, web伺服器無法直接獲取到客 戶端真實的IP地址。 # $remote_addr獲取的是反向代理的IP地址。 反向代理伺服器在轉發請求的http頭資訊中, # 增加X-Forwarded-For資訊,用來記錄客戶端IP地址和客戶端請求的伺服器地址。
使用fpm打包
# 1.獲取fpm工具 [root@web01 ~]# wget http://test.driverzeng.com/other/fpm-1.3.3.x86_64.tar.gz # 2.安裝Ruby環境 [root@web01 ~]# yum -y install ruby rubygems ruby-devel # 3.解壓fpm工具 [root@web01 ~]# tar xf fpm-1.3.3.x86_64.tar.gz # 4.檢視gem源 [root@web01 ~]# gem source list # 5.追加阿里雲的gem源 [root@web01 ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ # 6.刪除國外源 [root@web01 ~]# gem sources --remove https://rubygems.org/ # 7.安裝fpm工具 [root@web01 ~]# gem install *.gem ## 儲存nginx的依賴包 yum install -y openssl-devel pcre-devel zlib-devel --downloadonly --downloaddir=/tmp ## 原始碼安裝nginx [root@web01 ~]# wget https://nginx.org/download/nginx-1.20.1.tar.gz [root@web01 ~]# mkdir /app [root@web01 ~]# tar xf nginx-1.20.1.tar.gz [root@web01 ~]# ./configure --prefix=/app/nginx-1.20.1 --with-compat --with-file-aio - -with-threads --with-http_addition_module --with-http_auth_request_module --withhttp_dav_module --with-http_flv_module --with-http_gunzip_module --withhttp_gzip_static_module --with-http_mp4_module --with-http_random_index_module --withhttp_realip_module --with-http_secure_link_module --with-http_slice_module --withhttp_ssl_module --with-http_stub_status_module --with-http_sub_module --withhttp_v2_module --with-mail --with-mail_ssl_module --with-stream --withstream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --withcc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protectorstrong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' -- with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' [root@web01 nginx-1.20.1]# make && make install #!/bin/bash groupadd www -g 666 useradd www -u 666 -g 666 -s /sbin/nologin -M echo ' [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking ExecStart=/app/nginx/sbin/nginx ExecReload=/app/nginx/sbin/nginx -s reload ExecStop=/app/nginx/sbin/nginx -s stop [Install] WantedBy=multi-user.target' > /usr/lib/systemd/system/nginx.service ln -s /app/nginx-1.20.1 /app/nginx