网站部署

时间: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

原文地址:https://www.cnblogs.com/wkyydsnb/p/15114587.html