Your commit message

This commit is contained in:
zeaslity
2024-11-27 10:33:20 +08:00
commit 080c7bb97f
911 changed files with 168439 additions and 0 deletions

165
nginx/addNginxProxy copy.sh Normal file
View File

@@ -0,0 +1,165 @@
#!/bin/bash
# 添加了端口占用的检测
# todo
# 对某一代理内容的删除
# 当运行时, 可以传入额外的参数
## ./runParams.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
#########color code#############
RED="31m" # Error message
GREEN="32m" # Success message
YELLOW="33m" # Warning message
BLUE="36m" # Info message
###############color echo func#################
colorEcho() {
echo -e "\033[${1}${@:2}\033[0m" 1>&2
}
Help() {
cat - 1>&2 <<EOF
本脚本的用法如下:
[-tcp t] <代理端口> <需要转发的IP> <需要转发的端口>
[-http] <反向代理域名> <代理端口> <反代的IP> <反代的端口>
[-h -help]
-tcp/t <代理端口>代表本机的端口 <需要转发的IP>代表反向代理的ip地址
<需要转发的端口>代表反向代理的端口
-http <反向代理域名>代表转发的url <代理端口>代表本机的端口
<反代的IP>代表反向代理的ip地址 <反代的端口>代表反向代理的端口
-h/help 打印本说明文档
例子:./addNginxProxy.sh -tcp 9500 192.168.1.248 80
即为将本地9500端口 转发至 192.168.1.248的80端口
EOF
}
checkPortInUse(){
# 如果端口被占用则返回错误
# 如果端口未占用则返回0
netstat -ntlp | awk '{print $4}' | cut -d ":" -f 2 | sed -n "3,+99999p"
if [[ `netstat -ntlp | awk '{print $4}' | cut -d ":" -f 2 | sed -n "3,+99999p" | grep -w ${FRONT_PROXY_PORT} &>/dev/null` -eq 0 ]]
then
colorEcho ${RED} "你想要使用的代理端口 ${FRONT_PROXY_PORT} 已被占用,请重新选用端口!!"
return 23
else
return 0
fi
}
addPortForward() {
#判断REVERSE_PROXY_IP是否符合IP的规格
#判断REVERSE_PROXY_PORT是否被占用
## 端口转发模板文件简单,直接写入此处!!
cat > /etc/nginx/conf.d/stream/${FRONT_PROXY_PORT}_${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf <<EOF
server {
listen ${FRONT_PROXY_PORT};
proxy_pass ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT};
}
EOF
if [[ -a /etc/nginx/conf.d/stream/${FRONT_PROXY_PORT}_${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf ]]; then
colorEcho ${GREEN} "端口转发配置成功!!"
nginx -t && nginx -s reload
if [[ $? -eq 0 ]];then
LOCAL_INTERNAL_IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/')
colorEcho ${GREEN} "nignx已成功重启"
colorEcho ${BLUE} "端口转发为: ${LOCAL_INTERNAL_IP}:${FRONT_PROXY_PORT} >>>> ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT}"
else
colorEcho ${RED} "nginx重启失败请检查是否端口已被使用"
fi
else
colorEcho ${RED} "端口转发文件添加失败,请手动添加!!"
return 34
fi
return 0
}
addReverProxy() {
#判断REVERSE_PROXY_IP是否符合IP的规格
#判断REVERSE_PROXY_PORT是否被占用
# 读取反向代理的模板然后写入相应的特定反向代理文件
if [[ -a /etc/nginx/conf.d/reverse_proxy_demo ]]
then
cat > /etc/nginx/conf.d/${REVERSE_PROXY_SERVER_NAME}_${FRONT_PROXY_PORT}-${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf < /etc/nginx/conf.d/reverse_proxy_demo
else
colorEcho ${RED} "反向代理的模板文件丢失!!! 无法添加反向代理!"
return 45
fi
if [[ -a /etc/nginx/conf.d/${REVERSE_PROXY_SERVER_NAME}_${FRONT_PROXY_PORT}-${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf ]]; then
sed -i -e "s/\${REVERSE_PROXY_SERVER_NAME}/${REVERSE_PROXY_SERVER_NAME}/g" \
-e "s/\${FRONT_PROXY_PORT}/${FRONT_PROXY_PORT}/g" \
-e "s/\${REVERSE_PROXY_IP}/${REVERSE_PROXY_IP}/g" \
-e "s/\${REVERSE_PROXY_PORT}/${REVERSE_PROXY_PORT}/g" \
/etc/nginx/conf.d/${REVERSE_PROXY_SERVER_NAME}_${FRONT_PROXY_PORT}-${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf
colorEcho ${GREEN} "反向代理文件添加成功!!"
nginx -t && nginx -s reload
if [[ $? -eq 0 ]];then
colorEcho ${GREEN} "nignx已成功重启"
colorEcho ${BLUE} "反向代理为: ${REVERSE_PROXY_SERVER_NAME}:${FRONT_PROXY_PORT} >>>> ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT}"
else
colorEcho ${RED} "nginx重启失败请检查是否端口已被使用"
fi
else
colorEcho ${RED} "反向代理配置文件添加失败,请手动添加!!"
return 34
fi
return 0
}
#########################
if [[ $# > 0 ]]
then
case "$1" in
-tcp | -t)
if [[ $# == 4 ]]; then
FRONT_PROXY_PORT="${2}"
REVERSE_PROXY_IP="${3}"
REVERSE_PROXY_PORT="${4}"
if [[ `checkPortInUse` -eq 0 ]]
then
addPortForward
else
return 23
fi
else
colorEcho ${RED} "输入的参数有误,请重新输入!"
return 123
fi
;;
-h | --help)
Help
;;
-http)
if [[ $# == 5 ]]; then
REVERSE_PROXY_SERVER_NAME="${2}"
FRONT_PROXY_PORT="${3}"
REVERSE_PROXY_IP="${4}"
REVERSE_PROXY_PORT="${5}"
if [[ `checkPortInUse -ne 0` ]]
then
addReverProxy
fi
else
colorEcho ${RED} "输入的参数有误,请重新输入!"
return 123
fi
;;
*)
# unknown option
colorEcho ${RED} "输入的参数不正确!"
Help
return 1
;;
esac
else
colorEcho ${BLUE} "请输入参数!!本脚本的用法如下!!"
Help
fi

128
nginx/addNginxProxy.sh Normal file
View File

@@ -0,0 +1,128 @@
#!/bin/bash
# 当运行时, 可以传入额外的参数
## ./runParams.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
#########color code#############
RED="31m" # Error message
GREEN="32m" # Success message
YELLOW="33m" # Warning message
BLUE="36m" # Info message
###############color echo func#################
colorEcho() {
echo -e "\033[${1}${@:2}\033[0m" 1>&2
}
Help() {
cat - 1>&2 <<EOF
./addNginxProxy.sh [-tcp t] <FRONT_PROXY_PORT> <REVERSE_PROXY_IP> <REVERSE_PROXY_PORT>
./addNginxProxy.sh [-http] <REVERSE_PROXY_SERVER_NAME> <FRONT_PROXY_PORT> <REVERSE_PROXY_IP> <REVERSE_PROXY_PORT>
./addNginxProxy.sh [-h -help]
-tcp/t <FRONT_PROXY_PORT>代表本机的端口 <REVERSE_PROXY_IP>代表反向代理的ip地址 <REVERSE_PROXY_PORT>代表反向代理的端口
-http <REVERSE_PROXY_SERVER_NAME>代表转发的url <REVERSE_PROXY_IP>代表反向代理的ip地址 <REVERSE_PROXY_PORT>代表反向代理的端口
-h/help 显示本说明
EOF
}
addPortForward() {
#判断FRONT_PROXY_PORT是否被占用
#判断REVERSE_PROXY_IP是否符合IP的规格
#判断REVERSE_PROXY_PORT是否被占用
## 端口转发模板文件简单,直接写入此处!!
cat > /etc/nginx/conf.d/stream/${FRONT_PROXY_PORT}_${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf <<EOF
server {
listen ${FRONT_PROXY_PORT};
proxy_pass ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT};
}
EOF
if [[ -a /etc/nginx/conf.d/stream/${FRONT_PROXY_PORT}_${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf ]]; then
colorEcho ${GREEN} "端口转发配置成功!!"
nginx -t && nginx -s reload
if [[ $? -eq 0 ]];then
LOCAL_INTERNAL_IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/')
colorEcho ${GREEN} "nignx已成功重启"
colorEcho ${BLUE} "端口转发为: ${LOCAL_INTERNAL_IP}:${FRONT_PROXY_PORT} >>>> ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT}"
else
colorEcho ${RED} "nginx重启失败请检查是否端口已被使用"
fi
else
colorEcho ${RED} "端口转发文件添加失败,请手动添加!!"
return 34
fi
return 0
}
addReverProxy() {
#判断FRONT_PROXY_PORT是否被占用
#判断REVERSE_PROXY_IP是否符合IP的规格
#判断REVERSE_PROXY_PORT是否被占用
# 读取反向代理的模板然后写入相应的特定反向代理文件
if [[ -a /etc/nginx/conf.d/reverse_proxy_demo ]]
then
cat > /etc/nginx/conf.d/${REVERSE_PROXY_SERVER_NAME}_${FRONT_PROXY_PORT}-${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf < /etc/nginx/conf.d/reverse_proxy_demo
else
colorEcho ${RED} "反向代理的模板文件丢失!!! 无法添加反向代理!"
return 45
fi
if [[ -a /etc/nginx/conf.d/${REVERSE_PROXY_SERVER_NAME}_${FRONT_PROXY_PORT}-${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf ]]; then
sed -i -e "s/\${REVERSE_PROXY_SERVER_NAME}/${REVERSE_PROXY_SERVER_NAME}/g" \
-e "s/\${FRONT_PROXY_PORT}/${FRONT_PROXY_PORT}/g" \
-e "s/\${REVERSE_PROXY_IP}/${REVERSE_PROXY_IP}/g" \
-e "s/\${REVERSE_PROXY_PORT}/${REVERSE_PROXY_PORT}/g" \
/etc/nginx/conf.d/${REVERSE_PROXY_SERVER_NAME}_${FRONT_PROXY_PORT}-${REVERSE_PROXY_IP}::${REVERSE_PROXY_PORT}.conf
colorEcho ${GREEN} "反向代理文件添加成功!!"
nginx -t && nginx -s reload
if [[ $? -eq 0 ]];then
colorEcho ${GREEN} "nignx已成功重启"
colorEcho ${BLUE} "反向代理为: ${REVERSE_PROXY_SERVER_NAME}:${FRONT_PROXY_PORT} >>>> ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT}"
else
colorEcho ${RED} "nginx重启失败请检查是否端口已被使用"
fi
else
colorEcho ${RED} "反向代理配置文件添加失败,请手动添加!!"
return 34
fi
return 0
}
#########################
if [[ $# > 0 ]]
then
case "$1" in
-tcp | -t)
if [[ $# == 4 ]]; then
FRONT_PROXY_PORT="${2}"
REVERSE_PROXY_IP="${3}"
REVERSE_PROXY_PORT="${4}"
addPortForward
else
colorEcho ${RED} "输入的参数有误,请重新输入!"
return 123
fi
;;
-h | --help)
Help
;;
-http)
if [[ $# == 5 ]]; then
REVERSE_PROXY_SERVER_NAME="${2}"
FRONT_PROXY_PORT="${3}"
REVERSE_PROXY_IP="${4}"
REVERSE_PROXY_PORT="${5}"
addReverProxy
else
colorEcho ${RED} "输入的参数有误,请重新输入!"
return 123
fi
;;
*)
# unknown option
colorEcho ${RED} "输入的参数不正确!"
Help
return 1
;;
esac
fi

View File

@@ -0,0 +1,94 @@
ADD file:46ad43b4984bcf49c5a888ff3628f23161f55cd1fb062f469e707100c97fa254 in /
CMD ["/bin/sh"]
LABEL maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>
ENV NGINX_VERSION=1.19.4
ENV NJS_VERSION=0.4.4
ENV PKG_RELEASE=1
RUN /bin/sh -c set -x \
&& addgroup -g 101 -S nginx \
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
&& apkArch="$(cat /etc/apk/arch)" \
&& nginxPackages=" \
nginx=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-xslt=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-geoip=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-image-filter=${NGINX_VERSION}-r${PKG_RELEASE} \
nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-r${PKG_RELEASE} " \
&& case "$apkArch" in x86_64) set -x \
&& KEY_SHA512="e7fa8303923d9b95db37a77ad46c68fd4755ff935d0a534d26eba83de193c76166c68bfe7f65471bf8881004ef4aa6df3e34689c305662750c0172fca5d8552a *stdin" \
&& apk add --no-cache --virtual .cert-deps openssl \
&& wget -O /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub \
&& if [ "$(openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout | openssl sha512 -r)" = "$KEY_SHA512" ]; then\
echo "key verification succeeded!"; \
mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/; \
else \
echo "key verification failed!"; \
exit 1; \
fi \
&& apk del .cert-deps \
&& apk add -X "https://nginx.org/packages/mainline/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" --no-cache $nginxPackages ;; *) set -x \
&& tempDir="$(mktemp -d)" \
&& chown nobody:nobody $tempDir \
&& apk add --no-cache --virtual .build-deps\
gcc \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
libedit-dev \
mercurial \
bash \
alpine-sdk \
findutils \
&& su nobody -s /bin/sh -c "\
export HOME=${tempDir}\
&& cd ${tempDir}\
&& hg clone https://hg.nginx.org/pkg-oss\
&& cd pkg-oss\
&& hg up ${NGINX_VERSION}-${PKG_RELEASE}\
&& cd alpine\
&& make all\
&& apk index -o ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz ${tempDir}/packages/alpine/${apkArch}/*.apk\
&& abuild-sign -k ${tempDir}/.abuild/abuild-key.rsa ${tempDir}/packages/alpine/${apkArch}/APKINDEX.tar.gz\
"\
&& cp ${tempDir}/.abuild/abuild-key.rsa.pub /etc/apk/keys/ \
&& apk del .build-deps \
&& apk add -X ${tempDir}/packages/alpine/ --no-cache $nginxPackages \
;; \
esac \
&& if [ -n "$tempDir" ]; then rm -rf "$tempDir"; fi \
&& if [ -n "/etc/apk/keys/abuild-key.rsa.pub" ]; then \
rm -f /etc/apk/keys/abuild-key.rsa.pub; fi \
&& if [ -n "/etc/apk/keys/nginx_signing.rsa.pub" ]; \
then rm -f /etc/apk/keys/nginx_signing.rsa.pub; fi \
&& apk add --no-cache --virtual .gettext gettext \
&& mv /usr/bin/envsubst /tmp/ \
&& runDeps="$( scanelf --needed --nobanner /tmp/envsubst | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' | sort -u | xargs -r apk info --installed | sort -u )" \
&& apk add --no-cache $runDeps && apk del .gettext \
&& mv /tmp/envsubst /usr/local/bin/ \
&& apk add --no-cache tzdata \
&& apk add --no-cache curl ca-certificates \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& mkdir /docker-entrypoint.d
COPY file:e7e183879c35719c18aa7f733651029fbcc55f5d8c22a877ae199b389425789e in /
COPY file:13577a83b18ff90a0f97a15cd6380790a5f5288c651fa08708ff64d3f1595861 in /docker-entrypoint.d
COPY file:0fd5fca330dcd6a7de297435e32af634f29f7132ed0550d342cad9fd20158258 in /docker-entrypoint.d
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["nginx" "-g" "daemon off;"]

View File

@@ -0,0 +1,49 @@
user nginx;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
client_max_body_size 16M;
# MIME
include mime.types;
default_type application/octet-stream;
# Logging
log_format log_json '{'
'"remote_addr": "$remote_addr", '
'"ident": "-", '
'"user": "$remote_user", '
'"timestamp": "$time_local", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"referer": "$http_referer", '
'"agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for"'
' }';
access_log /var/log/nginx/access.log log_json;
error_log /var/log/nginx/error.log warn;
# reverse proxy/server configs
include /etc/nginx/conf.d/*.conf;
}
# port forward configs
stream{
include /etc/nginx/conf.d/stream/*.conf;
}

View File

@@ -0,0 +1,37 @@
server {
# ${REVERSE_PROXY_SERVER_NAME}
listen ${FRONT_PROXY_PORT};
server_name ${REVERSE_PROXY_SERVER_NAME};
# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
# logging
access_log /var/log/nginx/${REVERSE_PROXY_SERVER_NAME}.access.log;
error_log /var/log/nginx/${REVERSE_PROXY_SERVER_NAME}.error.log warn;
# reverse proxy
location / {
proxy_pass http://${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT};
proxy_cache_bypass $http_upgrade;
# Proxy headers
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;
# Proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}

View File

@@ -0,0 +1,4 @@
server {
listen ${FRONT_PROXY_PORT};
proxy_pass ${REVERSE_PROXY_IP}:${REVERSE_PROXY_PORT};
}

141
nginx/编译安装nginx.sh Normal file
View File

@@ -0,0 +1,141 @@
#!/bin/bash
nginx_version="nginx-1.19.4"
openssl_version="openssl-openssl-3.0.0-alpha8"
nginx_prefix="/etc/nginx"
nginx_config="${nginx_prefix}/conf.d/"
nginx_is_installed=""
#判断是否已经安装
check_is_installed(){
if [ -d $nginx_config ]; then
nginx_is_installed=1
else
nginx_is_installed=0
fi
}
remove_nginx(){
systemctl stop nginx
${nginx_prefix}/sbin/nginx -s stop
pkill -9 nginx
systemctl disable nginx
rm -rf /etc/systemd/system/nginx.service
systemctl daemon-reload
rm -rf ${nginx_prefix}
}
#安装nignx
install_nginx()
{
green "正在编译和安装nginx。。。。"
if ! wget -O ${nginx_version}.tar.gz https://nginx.org/download/${nginx_version}.tar.gz; then
red "获取nginx失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
tar -zxf ${nginx_version}.tar.gz
if ! wget -O ${openssl_version}.tar.gz https://github.com/openssl/openssl/archive/${openssl_version#*-}.tar.gz; then
red "获取openssl失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
tar -zxf ${openssl_version}.tar.gz
cd ${nginx_version}
sed -i "s/OPTIMIZE[ \t]*=>[ \t]*'-O'/OPTIMIZE => '-O3'/g" src/http/modules/perl/Makefile.PL
./configure \
--prefix=${nginx_prefix} \
--with-openssl=../$openssl_version \
--with-openssl-opt="enable-ec_nistp_64_gcc_128 shared threads zlib-dynamic sctp" \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--with-pcre \
--with-libatomic \
--with-compat \
--with-cpp_test_module \
--with-google_perftools_module \
--with-file-aio \
--with-threads \
--with-poll_module \
--with-select_module \
--with-cc-opt="-Wno-error -g0 -O3"
# 详细的 nginx-module说明https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#dependencies
if ! make; then
red "nginx编译失败"
yellow "请尝试更换系统建议使用Ubuntu最新版系统"
exit 1
fi
remove_nginx
make install
cd ..
}
config_service_nginx(){
systemctl disable nginx
rm -rf /etc/systemd/system/nginx.service
cat > /etc/systemd/system/nginx.service << EOF
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
User=root
ExecStartPre=/bin/rm -rf /dev/shm/nginx_unixsocket
ExecStartPre=/bin/mkdir /dev/shm/nginx_unixsocket
ExecStartPre=/bin/chmod 711 /dev/shm/nginx_unixsocket
ExecStartPre=/bin/rm -rf /dev/shm/nginx_tcmalloc
ExecStartPre=/bin/mkdir /dev/shm/nginx_tcmalloc
ExecStartPre=/bin/chmod 0777 /dev/shm/nginx_tcmalloc
ExecStart=${nginx_prefix}/sbin/nginx
ExecStop=${nginx_prefix}/sbin/nginx -s stop
ExecStopPost=/bin/rm -rf /dev/shm/nginx_tcmalloc
ExecStopPost=/bin/rm -rf /dev/shm/nginx_unixsocket
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
chmod 0644 /etc/systemd/system/nginx.service
systemctl daemon-reload
systemctl enable nginx
}
main(){
## 检查nginx是否已经安装
}
main