内容介绍
1 分页介绍
2 BBR
3 升级内核
4 部署SS
5 部署PPTP_VPN
6 部署FRPS
7 部署LNMP
8 创建NGINX配置文件
9 创建NGINX默认配置模板文件
10 创建NGINX中调度PHP的配置文件
11 创建NGINX主程序配置文件nginx.conf
12 创建NGINX虚拟主机配置文件,80/443同时访问,参考并修改为自定义域名
13 创建NGINX虚拟主机配置文件,80通过301转向443,www默认访问FRPS映射的远端服务器,远端服务器虚拟主机配置文件
14 创建NGINX开启SSL相关文件及配置文件,创建数据库
15 前台后台部署网站源码,安装PHP扩展,提高WP上传文件大小
16 远端FRPC配置,总结,参考文章
目标效果
浏览器输入访问公网IP,不跳转任何虚拟域名,同IP可配置多个域名,不会影响彼此。
浏览器输入访问mydomain.com,在VPS上,进行301跳转,转向VPS的443,进行安全高速访问。
浏览器输入访问www.mydomain.com,在VPS上,进行精确匹配后,交给FRPS进程进行处理。
FRPS进程同后端服务器(N1)存在数据关联,直接由后端服务器(N1)响应请求。
目录准备mkdir /data
如果已存在,不必执行
VPS-SS
# SS之开启BBR
## CENTOS7.6的VPS系统内核需要升级到3.12以上
### 查看内核
cat /etc/redhat-release
uname -r
### 浏览器查看源列表,确认下方导入RPM为最新
http://elrepo.org/linux/kernel/el7/x86_64/RPMS/
### 导入并安装最新的源
rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
### 列出内核列表
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
### 安装新内核
yum -y --enablerepo=elrepo-kernel install kernel-ml
### 查看引导顺序
egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
### 设置新内核引导
grub2-set-default 0
### 重启后查看内核
reboot
uname -r
## 设置BBR转发、IPV4转发
echo 'net.core.default_qdisc = fq' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_congestion_control = bbr' >> /etc/sysctl.conf
sed -i '/net.ipv4.ip_forward/ s/\(.*= \).*/\11/' /etc/sysctl.conf
## 生效配置并确认
sysctl -p
sysctl net.ipv4.tcp_available_congestion_control
lsmod | grep bbr
cat /etc/sysctl.conf | grep net.ipv4.ip_forward
VPS-DOCKER部署
# 安装DOCKER环境
## CENTOS官方YUM方式
### 移除组件
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
### 增加源
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
### 安装组件
yum install -y docker-ce \
docker-ce-cli \
containerd.io
### 启动和开机启动
systemctl enable docker
systemctl start docker
## 或,就看清,是或,CENTOS官方脚本安装
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
VPS-SS
# 使用DOCKER搭建SS服务
## 拉取镜像
docker pull taterli/s-s-tiny
## 部署SS
docker run \
-p 8388:1080/tcp \
-p 8388:1080/udp \
-e PASSWORD='password' \
--cpus 0.1 \
--restart=always \
--name ss \
-d taterli/s-s-tiny
加密方式是默认是aes-256-gcm,根据需要可以增加CPU的百分比,端口、密码自行更改
VPS-P_P_T_P_V_P_N,去掉_,再执行
# 拉取镜像
docker pull mobtitude/v_p_n_-_p_p_t_p
# 创建配置文件
cat <<EOF | tee /data/chap-secrets
# Secrets for authentication using PAP
# client server secret acceptable local IP addresses
username * password *
EOF
# 部署P_P_T_P
docker run \
-p 1723:1723 \
-v /data/chap-secrets:/etc/ppp/chap-secrets \
--privileged \
--net=host \
--restart always \
--name p_p_t_p \
-d mobtitude/v_p_n_-_p_p_t_p
VPS-FRPS
# 使用DOCKER搭建FRP
## 拉取镜像
docker pull cloverzrg/frps-docker
## 创建配置文件
cat <<EOF | tee /data/frps.ini
# [common] is integral section
[common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
bind_addr = 0.0.0.0
bind_port = 7000
# udp port used for kcp protocol, it can be same with 'bind_port'
# if not set, kcp is disabled in frps
kcp_bind_port = 7000
# if you want to configure or reload frps by dashboard, dashboard_port must be set
dashboard_port = 7500
# dashboard assets directory(only for debug mode)
dashboard_user = admin
dashboard_pwd = admin
# assets_dir = ./static
vhost_http_port = 8000
vhost_https_port = 8443
# console or real logFile path like ./frps.log
log_file = /dev/null
# debug, info, warn, error
log_level = info
log_max_days = 3
# auth token
token = token
# only allow frpc to bind ports you list, if you set nothing, there won't be any limit
#allow_ports = 1-65535
# pool_count in each proxy will change to max_pool_count if they exceed the maximum value
max_pool_count = 50
# if tcp stream multiplexing is used, default is true
tcp_mux = true
EOF
## 部署FRP
docker run \
-p 6000:6000 \
-p 7000:7000 \
-p 7500:7500 \
-p 8000:8000 \
-p 8443:8443 \
-v /data/frps.ini:/conf/frps.ini \
--restart=always \
--name frps \
-d cloverzrg/frps-docker
## 额外配置(自己选择要不要启用,需要CS两端同时增加)
frps.ini
[common]
privilege_mode = true
privilege_token = 12345678
frpc.ini
[common]
privilege_token = 12345678
VPS-LNMP
# 使用DOCKER搭建LNMP服务
## 拉取镜像
docker pull nginx
docker pull mariadb
docker pull php:fpm
docker pull biarms/phpmyadmin # N1用此(ARM)
docker pull phpmyadmin/phpmyadmin # VPS用此(X86_64)
## 部署LNMP
### 创建网络(可选操作,后续并未将进程加入此网络中,需要加入,手动添加--network lnmp)
docker network create lnmp
### 部署mariadb(不公开端口,内部LINK互连即可,相对安全)
docker run \
-v /data/mysql:/var/lib/mysql \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=root \
--restart=always \
--name mariadb \
-d mariadb
VPS可以考虑限制内存使用率,密码保持默认,部署之后再修改
### 准备php文件(准备一次即可,多次部署不必反复准备)
mkdir -p /data/php/php-fpm.d
docker run --name php -d php:fpm
docker cp php:/usr/local/etc/php/php.ini-production /data/php/php.ini
docker cp php:/usr/local/etc/php-fpm.d/www.conf /data/php/php-fpm.d/www.conf
docker stop php
docker rm php
### 部署php-fpm(采用LINK的方式直连DB)
docker run \
-v /data/www:/var/www/html \
-v /data/php/php.ini:/usr/local/etc/php/php.ini \
-v /data/php/php-fpm.d/www.conf:/usr/local/etc/php-fpm.d/www.conf \
-v /etc/localtime:/etc/localtime:ro \
--restart=always \
--name php \
--link mariadb \
--cpus 0.7 \
-d php:fpm
N1可以限制CPU占用率,否则峰值CPU会在200%+,以此方式的控制PHP处理时,一直在70%以下
### 部署nginx(因PHP未公开端口,需要LINK直连PHP,实现FASTCGI中PHP:9000的通讯)
docker run \
-p 80:80 \
-p 443:443 \
-v /data/www:/usr/share/nginx/html \
-v /data/nginx:/etc/nginx \
-v /etc/localtime:/etc/localtime:ro \
--restart=always \
--name nginx \
--link php \
-d nginx
### 安装PHP扩展(使得PHP可以操作数据库,记得重启下PHP)
docker exec -it php bash
docker-php-ext-install mysqli
exit
### 部署phpmyadmin(采用LINK的方式直连DB)
docker run \
-p 8080:80 \
-v /etc/localtime:/etc/localtime:ro \
--restart=always \
--name pma \
--link mariadb:db \
-d phpmyadmin/phpmyadmin #x86_64
-d biarms/phpmyadmin #arm
成功,但运行失败,原因,目录中缺少配置文件,继续补充配置文件后,重启DOCKER进程即可。
## 创建配置文件(可选,共创建以下文件)
### 以下内容可创建,也可以直接从容器中复制出来
touch fastcgi_params
touch scgi_params
touch uwsgi_params
touch mime.types
touch win-utf
touch koi-utf
touch koi-win
### 以下内容会在nginx.conf中引用
touch set_worker.conf
touch set_event.conf
touch set_client.conf
touch set_sendfile.conf
touch set_tcp.conf
touch set_gzip.conf
touch set_fastcgi.conf
touch nginx.conf
### 以下内容会在域名配置中引用
touch pathinfo.conf
touch enable-php-pathinfo-mydomain.com.conf
touch mydomain.com.conf
#### 如果需要重写路径,可选择创建下面
touch rewrite_wordpress.conf
touch rewrite_typecho.conf
### 以下内容为样板,不会引用
touch fastcgi.conf
touch enable-php.conf
touch enable-php-pathinfo.conf
## 准备配置文件
### 模块文件
cat <<EOF | tee /data/nginx/set_worker.conf
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 51200;
EOF
# 默认值为1024,N1需要更改
cat <<EOF | tee /data/nginx/set_event.conf
events {
use epoll;
worker_connections 51200;
multi_accept off;
accept_mutex off;
}
EOF
# 默认值为1024,N1需要更改
cat <<EOF | tee /data/nginx/set_client.conf
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
EOF
cat <<EOF | tee /data/nginx/set_sendfile.conf
sendfile on;
sendfile_max_chunk 512k;
EOF
cat <<EOF | tee /data/nginx/set_tcp.conf
tcp_nodelay on;
tcp_nopush on;
EOF
cat <<EOF | tee /data/nginx/set_gzip.conf
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
EOF
cat <<EOF | tee /data/nginx/set_fastcgi.conf
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
EOF
cat <<EOF | tee /data/nginx/fastcgi.conf
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param QUERY_STRING \$query_string;
fastcgi_param REQUEST_METHOD \$request_method;
fastcgi_param CONTENT_TYPE \$content_type;
fastcgi_param CONTENT_LENGTH \$content_length;
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
fastcgi_param REQUEST_URI \$request_uri;
fastcgi_param DOCUMENT_URI \$document_uri;
fastcgi_param DOCUMENT_ROOT \$document_root;
fastcgi_param SERVER_PROTOCOL \$server_protocol;
fastcgi_param REQUEST_SCHEME \$scheme;
fastcgi_param HTTPS \$https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
fastcgi_param REMOTE_ADDR \$remote_addr;
fastcgi_param REMOTE_PORT \$remote_port;
fastcgi_param SERVER_ADDR \$server_addr;
fastcgi_param SERVER_PORT \$server_port;
fastcgi_param SERVER_NAME \$server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=\$document_root/:/tmp/:/proc/";
EOF
下面几个文件可以从容器中复制出,也可以按以下内容创建
cat <<EOF | tee /data/nginx/fastcgi_params
fastcgi_param QUERY_STRING \$query_string;
fastcgi_param REQUEST_METHOD \$request_method;
fastcgi_param CONTENT_TYPE \$content_type;
fastcgi_param CONTENT_LENGTH \$content_length;
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
fastcgi_param REQUEST_URI \$request_uri;
fastcgi_param DOCUMENT_URI \$document_uri;
fastcgi_param DOCUMENT_ROOT \$document_root;
fastcgi_param SERVER_PROTOCOL \$server_protocol;
fastcgi_param REQUEST_SCHEME \$scheme;
fastcgi_param HTTPS \$https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
fastcgi_param REMOTE_ADDR \$remote_addr;
fastcgi_param REMOTE_PORT \$remote_port;
fastcgi_param SERVER_ADDR \$server_addr;
fastcgi_param SERVER_PORT \$server_port;
fastcgi_param SERVER_NAME \$server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
EOF
cat <<EOF | tee /data/nginx/scgi_params
scgi_param REQUEST_METHOD \$request_method;
scgi_param REQUEST_URI \$request_uri;
scgi_param QUERY_STRING \$query_string;
scgi_param CONTENT_TYPE \$content_type;
scgi_param DOCUMENT_URI \$document_uri;
scgi_param DOCUMENT_ROOT \$document_root;
scgi_param SCGI 1;
scgi_param SERVER_PROTOCOL \$server_protocol;
scgi_param REQUEST_SCHEME \$scheme;
scgi_param HTTPS \$https if_not_empty;
scgi_param REMOTE_ADDR \$remote_addr;
scgi_param REMOTE_PORT \$remote_port;
scgi_param SERVER_PORT \$server_port;
scgi_param SERVER_NAME \$server_name;
EOF
cat <<EOF | tee /data/nginx/uwsgi_params
uwsgi_param QUERY_STRING \$query_string;
uwsgi_param REQUEST_METHOD \$request_method;
uwsgi_param CONTENT_TYPE \$content_type;
uwsgi_param CONTENT_LENGTH \$content_length;
uwsgi_param REQUEST_URI \$request_uri;
uwsgi_param PATH_INFO \$document_uri;
uwsgi_param DOCUMENT_ROOT \$document_root;
uwsgi_param SERVER_PROTOCOL \$server_protocol;
uwsgi_param REQUEST_SCHEME \$scheme;
uwsgi_param HTTPS \$https if_not_empty;
uwsgi_param REMOTE_ADDR \$remote_addr;
uwsgi_param REMOTE_PORT \$remote_port;
uwsgi_param SERVER_PORT \$server_port;
uwsgi_param SERVER_NAME \$server_name;
EOF
### 多媒体文件
cat <<EOF | tee /data/nginx/mime.types
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
EOF
### 字体文件
cat <<EOF | tee /data/nginx/win-utf
# This map is not a full windows-1251 <> utf8 map: it does not
# contain Serbian and Macedonian letters. If you need a full map,
# use contrib/unicode2nginx/win-utf map instead.
charset_map windows-1251 utf-8 {
82 E2809A ; # single low-9 quotation mark
84 E2809E ; # double low-9 quotation mark
85 E280A6 ; # ellipsis
86 E280A0 ; # dagger
87 E280A1 ; # double dagger
88 E282AC ; # euro
89 E280B0 ; # per mille
91 E28098 ; # left single quotation mark
92 E28099 ; # right single quotation mark
93 E2809C ; # left double quotation mark
94 E2809D ; # right double quotation mark
95 E280A2 ; # bullet
96 E28093 ; # en dash
97 E28094 ; # em dash
99 E284A2 ; # trade mark sign
A0 C2A0 ; #
A1 D18E ; # capital Byelorussian short U
A2 D19E ; # small Byelorussian short u
A4 C2A4 ; # currency sign
A5 D290 ; # capital Ukrainian soft G
A6 C2A6 ; # borken bar
A7 C2A7 ; # section sign
A8 D081 ; # capital YO
A9 C2A9 ; # (C)
AA D084 ; # capital Ukrainian YE
AB C2AB ; # left-pointing double angle quotation mark
AC C2AC ; # not sign
AD C2AD ; # soft hypen
AE C2AE ; # (R)
AF D087 ; # capital Ukrainian YI
B0 C2B0 ; # °
B1 C2B1 ; # plus-minus sign
B2 D086 ; # capital Ukrainian I
B3 D196 ; # small Ukrainian i
B4 D291 ; # small Ukrainian soft g
B5 C2B5 ; # micro sign
B6 C2B6 ; # pilcrow sign
B7 C2B7 ; # ·
B8 D191 ; # small yo
B9 E28496 ; # numero sign
BA D194 ; # small Ukrainian ye
BB C2BB ; # right-pointing double angle quotation mark
BF D197 ; # small Ukrainian yi
C0 D090 ; # capital A
C1 D091 ; # capital B
C2 D092 ; # capital V
C3 D093 ; # capital G
C4 D094 ; # capital D
C5 D095 ; # capital YE
C6 D096 ; # capital ZH
C7 D097 ; # capital Z
C8 D098 ; # capital I
C9 D099 ; # capital J
CA D09A ; # capital K
CB D09B ; # capital L
CC D09C ; # capital M
CD D09D ; # capital N
CE D09E ; # capital O
CF D09F ; # capital P
D0 D0A0 ; # capital R
D1 D0A1 ; # capital S
D2 D0A2 ; # capital T
D3 D0A3 ; # capital U
D4 D0A4 ; # capital F
D5 D0A5 ; # capital KH
D6 D0A6 ; # capital TS
D7 D0A7 ; # capital CH
D8 D0A8 ; # capital SH
D9 D0A9 ; # capital SHCH
DA D0AA ; # capital hard sign
DB D0AB ; # capital Y
DC D0AC ; # capital soft sign
DD D0AD ; # capital E
DE D0AE ; # capital YU
DF D0AF ; # capital YA
E0 D0B0 ; # small a
E1 D0B1 ; # small b
E2 D0B2 ; # small v
E3 D0B3 ; # small g
E4 D0B4 ; # small d
E5 D0B5 ; # small ye
E6 D0B6 ; # small zh
E7 D0B7 ; # small z
E8 D0B8 ; # small i
E9 D0B9 ; # small j
EA D0BA ; # small k
EB D0BB ; # small l
EC D0BC ; # small m
ED D0BD ; # small n
EE D0BE ; # small o
EF D0BF ; # small p
F0 D180 ; # small r
F1 D181 ; # small s
F2 D182 ; # small t
F3 D183 ; # small u
F4 D184 ; # small f
F5 D185 ; # small kh
F6 D186 ; # small ts
F7 D187 ; # small ch
F8 D188 ; # small sh
F9 D189 ; # small shch
FA D18A ; # small hard sign
FB D18B ; # small y
FC D18C ; # small soft sign
FD D18D ; # small e
FE D18E ; # small yu
FF D18F ; # small ya
}
EOF
cat <<EOF | tee /data/nginx/koi-utf
# This map is not a full koi8-r <> utf8 map: it does not contain
# box-drawing and some other characters. Besides this map contains
# several koi8-u and Byelorussian letters which are not in koi8-r.
# If you need a full and standard map, use contrib/unicode2nginx/koi-utf
# map instead.
charset_map koi8-r utf-8 {
80 E282AC ; # euro
95 E280A2 ; # bullet
9A C2A0 ; #
9E C2B7 ; # ·
A3 D191 ; # small yo
A4 D194 ; # small Ukrainian ye
A6 D196 ; # small Ukrainian i
A7 D197 ; # small Ukrainian yi
AD D291 ; # small Ukrainian soft g
AE D19E ; # small Byelorussian short u
B0 C2B0 ; # °
B3 D081 ; # capital YO
B4 D084 ; # capital Ukrainian YE
B6 D086 ; # capital Ukrainian I
B7 D087 ; # capital Ukrainian YI
B9 E28496 ; # numero sign
BD D290 ; # capital Ukrainian soft G
BE D18E ; # capital Byelorussian short U
BF C2A9 ; # (C)
C0 D18E ; # small yu
C1 D0B0 ; # small a
C2 D0B1 ; # small b
C3 D186 ; # small ts
C4 D0B4 ; # small d
C5 D0B5 ; # small ye
C6 D184 ; # small f
C7 D0B3 ; # small g
C8 D185 ; # small kh
C9 D0B8 ; # small i
CA D0B9 ; # small j
CB D0BA ; # small k
CC D0BB ; # small l
CD D0BC ; # small m
CE D0BD ; # small n
CF D0BE ; # small o
D0 D0BF ; # small p
D1 D18F ; # small ya
D2 D180 ; # small r
D3 D181 ; # small s
D4 D182 ; # small t
D5 D183 ; # small u
D6 D0B6 ; # small zh
D7 D0B2 ; # small v
D8 D18C ; # small soft sign
D9 D18B ; # small y
DA D0B7 ; # small z
DB D188 ; # small sh
DC D18D ; # small e
DD D189 ; # small shch
DE D187 ; # small ch
DF D18A ; # small hard sign
E0 D0AE ; # capital YU
E1 D090 ; # capital A
E2 D091 ; # capital B
E3 D0A6 ; # capital TS
E4 D094 ; # capital D
E5 D095 ; # capital YE
E6 D0A4 ; # capital F
E7 D093 ; # capital G
E8 D0A5 ; # capital KH
E9 D098 ; # capital I
EA D099 ; # capital J
EB D09A ; # capital K
EC D09B ; # capital L
ED D09C ; # capital M
EE D09D ; # capital N
EF D09E ; # capital O
F0 D09F ; # capital P
F1 D0AF ; # capital YA
F2 D0A0 ; # capital R
F3 D0A1 ; # capital S
F4 D0A2 ; # capital T
F5 D0A3 ; # capital U
F6 D096 ; # capital ZH
F7 D092 ; # capital V
F8 D0AC ; # capital soft sign
F9 D0AB ; # capital Y
FA D097 ; # capital Z
FB D0A8 ; # capital SH
FC D0AD ; # capital E
FD D0A9 ; # capital SHCH
FE D0A7 ; # capital CH
FF D0AA ; # capital hard sign
}
EOF
cat <<EOF | tee /data/nginx/koi-win
charset_map koi8-r windows-1251 {
80 88 ; # euro
95 95 ; # bullet
9A A0 ; #
9E B7 ; # ·
A3 B8 ; # small yo
A4 BA ; # small Ukrainian ye
A6 B3 ; # small Ukrainian i
A7 BF ; # small Ukrainian yi
AD B4 ; # small Ukrainian soft g
AE A2 ; # small Byelorussian short u
B0 B0 ; # °
B3 A8 ; # capital YO
B4 AA ; # capital Ukrainian YE
B6 B2 ; # capital Ukrainian I
B7 AF ; # capital Ukrainian YI
B9 B9 ; # numero sign
BD A5 ; # capital Ukrainian soft G
BE A1 ; # capital Byelorussian short U
BF A9 ; # (C)
C0 FE ; # small yu
C1 E0 ; # small a
C2 E1 ; # small b
C3 F6 ; # small ts
C4 E4 ; # small d
C5 E5 ; # small ye
C6 F4 ; # small f
C7 E3 ; # small g
C8 F5 ; # small kh
C9 E8 ; # small i
CA E9 ; # small j
CB EA ; # small k
CC EB ; # small l
CD EC ; # small m
CE ED ; # small n
CF EE ; # small o
D0 EF ; # small p
D1 FF ; # small ya
D2 F0 ; # small r
D3 F1 ; # small s
D4 F2 ; # small t
D5 F3 ; # small u
D6 E6 ; # small zh
D7 E2 ; # small v
D8 FC ; # small soft sign
D9 FB ; # small y
DA E7 ; # small z
DB F8 ; # small sh
DC FD ; # small e
DD F9 ; # small shch
DE F7 ; # small ch
DF FA ; # small hard sign
E0 DE ; # capital YU
E1 C0 ; # capital A
E2 C1 ; # capital B
E3 D6 ; # capital TS
E4 C4 ; # capital D
E5 C5 ; # capital YE
E6 D4 ; # capital F
E7 C3 ; # capital G
E8 D5 ; # capital KH
E9 C8 ; # capital I
EA C9 ; # capital J
EB CA ; # capital K
EC CB ; # capital L
ED CC ; # capital M
EE CD ; # capital N
EF CE ; # capital O
F0 CF ; # capital P
F1 DF ; # capital YA
F2 D0 ; # capital R
F3 D1 ; # capital S
F4 D2 ; # capital T
F5 D3 ; # capital U
F6 C6 ; # capital ZH
F7 C2 ; # capital V
F8 DC ; # capital soft sign
F9 DB ; # capital Y
FA C7 ; # capital Z
FB D8 ; # capital SH
FC DD ; # capital E
FD D9 ; # capital SHCH
FE D7 ; # capital CH
FF DA ; # capital hard sign
}
EOF
下面的文件需要继续创建### 调度文件
cat <<EOF | tee /data/nginx/pathinfo.conf
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set \$path_info \$fastcgi_path_info;
fastcgi_param PATH_INFO \$path_info;
try_files \$fastcgi_script_name =404;
EOF
cat <<EOF | tee /data/nginx/enable-php.conf
location ~ [^/]\.php(/|$)
{
try_files \$uri =404;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
EOF
cat <<EOF | tee /data/nginx/enable-php-pathinfo.conf
location ~ [^/]\.php(/|$)
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}
EOF
有fastcgi.conf的地方,就会有坑,因为这是docker,不是编译,虽然采用的是军哥的配置文件,但是,相对引用的配置,是不可用的,已经碰了太多回壁了。因为是坑,所以保留它,警醒自己。
### 域名fastcgi文件,记得替换成自己的域名
cat <<EOF | tee /data/nginx/enable-php-pathinfo-mydomain.com.conf
location ~ [^/]\.php(/|$)
{
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/mydomain.com/\$fastcgi_script_name;
include fastcgi_params;
include pathinfo.conf;
}
EOF
此处我已经改为fastcgi_params,fastcgi.conf中的$document_root也换成了绝对路径,所以这是正确的配置。
### 重写文件
cat <<EOF | tee /data/nginx/rewrite_wordpress.conf
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ \$scheme://\$host\$uri/ permanent;
EOF
cat <<EOF | tee /data/nginx/rewrite_typecho.conf
if (!-e \$request_filename) {
rewrite ^(.*)$ /index.php\$1 last;
}
EOF
### 程序配置文件
cat <<EOF | tee /data/nginx/nginx.conf
user nginx;
#worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
#events {
# worker_connections 1024;
#}
include set_worker.conf;
pcre_jit on;
include set_event.conf;
#include /etc/nginx/modules/*.conf;
http {
#include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
#keepalive_timeout 65;
#gzip on;
include set_client.conf;
include set_sendfile.conf;
include set_tcp.conf;
include set_gzip.conf;
include set_fastcgi.conf;
server_tokens off;
ssl_prefer_server_ciphers on;
access_log off;
keepalive_timeout 60;
include mime.types;
server
{
listen 80 default_server reuseport;
#listen [::]:80 default_server ipv6only=on;
server_name _;
index index.html index.htm index.php;
root /usr/share/nginx/html;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
#include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
include /etc/nginx/conf.d/*.conf;
}
EOF
# 引用的虚拟主机文件,一定要在nginx.conf主配置之下,这样才能使得,访问公网IP,调用nginx.conf中的配置,然后才再再调用虚拟主机的配置。
# 如果配置顺序颠倒,会造成访问公网IP,直接调转虚拟主机配置的页面中。如果是多虚拟主机,是不希望访问公网IP,跳转到某个虚拟主机的页面的。
# 所以如此配置,保持相对独立。
### 虚拟主机配置文件,80与443同时可访问,不存在301跳转,不需要443或80,直接删除对应区块即可。
mkdir -p /data/nginx/conf.d/
cat <<EOF | tee /data/nginx/conf.d/mydomain.com.conf
server
{
listen 80;
#listen [::]:80;
server_name mydomain.com www.mydomain.com;
index index.html index.htm index.php default.html default.htm default.php;
root /usr/share/nginx/html/mydomain.com;
include rewrite_wordpress.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo-mydomain.com.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name mydomain.com www.mydomain.com;
index index.html index.htm index.php default.html default.htm default.php;
root /usr/share/nginx/html/mydomain.com;
ssl_certificate ssl.mydomain.com.crt;
ssl_certificate_key ssl.mydomain.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
ssl_dhparam dhparam.pem;
include rewrite_wordpress.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo-mydomain.com.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
EOF
下面的配置:访问主域80,通过301跳转443,访问子域www转向FRP后端服务器
mydomain.com.conf
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name mydomain.com;
index index.html index.htm index.php default.html default.htm default.php;
root /usr/share/nginx/html/mydomain.com;
ssl_certificate ssl.mydomain.com.crt;
ssl_certificate_key ssl.mydomain.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
ssl_dhparam dhparam.pem;
include rewrite_wordpress.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo-mydomain.com.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
server
{
listen 80;
server_name mydomain.com;
return 301 https://$server_name$request_uri;
access_log off;
}
server {
listen 80;
server_name www.mydomain.com;
location / {
proxy_pass http://www.mydomain.com:8000;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
access_log off;
}
FRP后端服务器虚拟主机配置
mydomain.com.conf
server
{
listen 80;
#listen [::]:80;
server_name www.mydomain.com;
index index.html index.htm index.php default.html default.htm default.php;
root /usr/share/nginx/html/mydomain.com;
include rewrite_wordpress.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo-mydomain.com.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
## 创建SSL访问校验文件(不需要443访问时,此项可选)
# 生成密钥文件,请参考上文openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
openssl dhparam -out /data/nginx/dhparam.pem 2048
## 上传证书文件
上传到真机目录/data/nginx/中,根据虚拟站点ssl配置进行命名即可,此处证书文件应该存在于
/data/nginx/ssl.domain.com.crt
/data/nginx/ssl.domain.com.key
## 重启动DOCKER进程
docker restart mariadb php nginx pma
## 放置空文件在根目录,不显示403
cat <<EOF | tee /data/www/index.html
<!DOCTYPE html>
EOF
## 更改MYSQL密码
浏览器访问http://ip地址:8080
使用root/root登录
对账户进行修改密码,更改%号的用户密码才有效果
如需要,同时创建新用户与数据库,并授权
数据库主机需要为任意主机%,localhost不可用
用户名:wordpress
主机名:%
密码:
创建与用户同名的数据库并授予所有权限
出于安全考虑,建议下载freeotp,进行双因素关联
# 搭建站点
## 后台安装站点源码
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar zxvf *.tar.gz -C /data/www/
rm -rf *.tar.gz
chown 33 -R /data/www/wordpress
mv /data/www/wordpress /data/www/mydomain.com
为什么是33,因为docker镜像中的nginx是用www-data运行的,www-data的ID是33
## 前台安装
http://mydomain.com
如果采用301跳转的配置,80访问会转成443。
录入站点、数据库信息,数据库写docker中mariadb的name,即mariadb。
## 成功安装,进入WORDPRESS,查看工具-站点健康,发现提示
警告 可选的模组bcmath未被安装或已被禁用。
警告 可选的模组exif未被安装或已被禁用。
警告 可选的模组imagick未被安装或已被禁用。
错误 必需的模组gd未被安装或已被禁用。
### 安装额外PHP扩展
docker exec -it php bash
docker-php-ext-install exif
docker-php-ext-install bcmath
GD扩展需要额外的组件,DOCKER镜像的PHP是debian10,因此需要更新源,才可继续安装,采用华为云
cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
sed -i "s@http://ftp.debian.org@https://mirrors.huaweicloud.com@g" /etc/apt/sources.list
sed -i "s@http://security.debian.org@https://mirrors.huaweicloud.com@g" /etc/apt/sources.list
官方有一步是安装https源,暂时忽略
apt-get install apt-transport-https ca-certificates安装https源
执行进行下面更新
apt-get update
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
下面的操作是源码编译,暂时忽略
docker-php-source extract #解压源码
cd /usr/src/php/ext/gd #gd源码文件夹
docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2 #准备编译
执行进行下面的安装
docker-php-ext-install gd
php -m | grep gd
# 最后安装比较麻烦的imagick
apt-get install -y libmagickwand-dev libmagickcore-dev
pecl install imagick
Please provide the prefix of Imagemagick installation [autodetect] : # 此处直接回车即可
You should add "extension=imagick.so" to php.ini # 提示放入php.ini中相应so文件
exit
echo extension=imagick.so >> /data/php/php.ini
### 增加导入wordpress的xml备份大小为50M
vi /data/php/php.ini
post_max_size = 50M
upload_max_filesize = 50M
## 重启动DOCKER进程
docker restart mariadb php nginx pma
再删除无用插件,无用主题,重新健康检查下
上述操作中,提到了FRPS代理后端,继续进行FRPS相关配置
## 远端服务器配置
### 映射内部主机到8000端口
系统:采用N1进行部署,刷小钢炮,或ARMBIAN
环境:安装并运行DOCKER,可以考虑安装web管理界面portainer
服务:用上面的方法,部署LNMP到N1中,PHPMYADMIN用ARM版本;NGINX映射端口时,需要映射8000:80
配置:N1中的WWW域名配置见上面
### 继续部署内网FRPC
安装并配置FRPC,在代理配置中,名称自定义,方式http,地址127.0.0.1,端口为nginx的映射端口8000,自定义域名为www.mydomain.com,保存即可。
### 放置源码至网站目录
同上
至此,实现了以下访问效果
浏览器输入访问公网IP,不跳转任何虚拟域名,同IP可配置多个域名,不会影响彼此。
浏览器输入访问mydomain.com,在VPS上,进行301跳转,转向VPS的443,进行安全高速访问。
浏览器输入访问www.mydomain.com,在VPS上,进行精确匹配后,交给FRPS进程进行处理。
FRPS进程同后端服务器(N1)存在数据关联,直接由后端服务器(N1)响应请求。
当主域和WWW子域为同内容时,可将本地服务作为备份站点。
同样,对于相册程序,也可通过此访问,进行跳转,实现无端口化访问(未测试,理论判断)。
例如
本端模式
本端nginx:pic.mydomain.com:80-->mydomain.com:8088
本端docker:相册:8088-->80
远端模式(可能不行,未测试)
本端nginx:pic.mydomain.com:80-->mydomain.com:8088
本端frps:vhost=8000
远端docker:相册:8088-->80
远端frpc:tcp 127.0.0.1 8088 8088
放一张后台运行的图,证明我的配置没有忽悠的成份。
# 参考文章
## 搭建
https://segmentfault.com/a/1190000010401846
http://www.kwor.cn/2017/04/p_p_t_p-v_p_n.html
## 组件
https://hub.docker.com/r/mobtitude/v_p_n-p_p_t_p
FRPS
## 搭建
https://www.jianshu.com/p/00c79df1aaf0
https://www.jianshu.com/p/0180ea415710
https://blog.csdn.net/u011054333/article/details/71507074
## 组件
https://hub.docker.com/r/cloverzrg/frps-docker
LNMP
## 建站
https://509509.xyz:82/index.php/archives/5/
https://www.right.com.cn/forum/thread-592460-1-1.html
https://www.jianshu.com/p/cd1636c94f9f
## 扩展
https://blog.csdn.net/wt1286331074/article/details/91425518
https://blog.csdn.net/bingbingtea/article/details/51746468
http://portal.digitser.cn/article-1867-3.html
https://www.zyku.net/gongju/1778.html
http://www.bubuko.com/infodetail-2160447.html
https://www.cnblogs.com/didi/p/3410934.html
https://www.zyku.net/gongju/1778.html
https://www.cnblogs.com/xzysaber/p/6526563.html
https://blog.csdn.net/diyiday/article/details/85049702
## 组件
https://hub.docker.com/r/ebspace/aarch64-phpmyadmin
https://hub.docker.com/r/biarms/phpmyadmin
## 数据库问题处理
https://blog.csdn.net/dwsMo2/article/details/80016236
https://cloud.tencent.com/developer/ask/177844
原文地址:https://www.right.com.cn/forum/thread-870156-1-1.html