# Openresty 部署 - nginx && centos编译
https://abc.htmltoo.com/thread-45866.htm
cd /data/site/docker/dockerfile/openresty-full-solution
docker build -t openresty .
docker run -d --name openresty --hostname tengine --restart=always -e TZ='Asia/Shanghai' --ulimit nofile=262144:262144 -v /data/site/docker/env/nginx/openresty/nginx.conf:/etc/nginx/nginx.conf:ro -v /data/site/docker/env/nginx/openresty/conf.d:/etc/nginx/conf.d/:ro -v /data/file/logs/openresty:/var/log/nginx -v /data/site:/data/site -v /data/file:/data/file --link mariadb --link php74 hub.htmltoo.com:5000/http:openresty
docker exec -it openresty /bin/bash
docker commit -m="update" -a="htmltoo.com" openresty hub.htmltoo.com:5000/http:openresty
docker push hub.htmltoo.com:5000/http:openresty
cd /data/site/docker/dockerfile/openresty-full-solution
docker build -t openresty .
docker run -d --name openresty --hostname tengine --restart=always -e TZ='Asia/Shanghai' --ulimit nofile=262144:262144 -v /data/site/docker/env/nginx/openresty/nginx.conf:/etc/nginx/nginx.conf:ro -v /data/site/docker/env/nginx/openresty/conf.d:/etc/nginx/conf.d/:ro -v /data/file/logs/openresty:/var/log/nginx -v /data/site:/data/site -v /data/file:/data/file --link mariadb --link php74 openresty
cat /data/site/docker/dockerfile/openresty-full-solution/Dockerfile
FROM ubuntu:20.04
#Update and install Dependencies
RUN apt update && apt install -y aptitude && aptitude install locales -y && apt-mark hold tzdata
RUN apt install -y build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev libssl-dev perl make curl wget net-tools curl git
#RUN apt install -y libxml2 python-lxml-doc python3-lxml python3-lxml-dbg libui-gxmlcpp-dev libui-gxmlcpp5v5
#RUN apt install -y libjpeg62-turbo-dev
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone;
RUN export \LANG=zh_CN.UTF-8 && sed -i 's/^# *\(zh_CN.UTF-8\)/\1/' /etc/locale.gen && locale-gen
# Set versions. Check http://openresty.org for latest version and bundled version of nginx.
ARG OPENRESTY_VERSION=1.21.4.3
ARG NGINX_VERSION=1.21.4
ARG OPENSSL_VERSION=3.2.0
ARG NPS_VERSION=1.13.35.2-stable
# PSOL library link might be changed, if container build failed for this problem , search the link in google and find new link
ARG PSOL=https://www.modpagespeed.com/release_archive/1.13.35.2/psol-1.13.35.2-x64.tar.gz
ARG PSOL_FILE=psol-1.13.35.2-x64.tar.gz
# ARG NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
WORKDIR /usr/local/src/
#Get all Build Dependencies and make them ready for building nignx and openresty
ADD http://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz ./
RUN tar -xzf openresty-${OPENRESTY_VERSION}.tar.gz && rm -rf openresty-${OPENRESTY_VERSION}.tar.gz
ADD https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz ./
RUN tar -xzf openssl-${OPENSSL_VERSION}.tar.gz && rm -f openssl-${OPENSSL_VERSION}.tar.gz
ADD https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}.zip ./
RUN unzip v${NPS_VERSION}.zip && rm -rf v${NPS_VERSION}.zip
WORKDIR /usr/local/src/incubator-pagespeed-ngx-${NPS_VERSION}
ADD ${PSOL} ./
RUN tar -xzf $PSOL_FILE && rm -rf $PSOL_FILE
RUN mv /usr/local/src/incubator-pagespeed-ngx-${NPS_VERSION} /usr/local/src/openresty-${OPENRESTY_VERSION}/bundle/nginx-${NGINX_VERSION}/
WORKDIR /usr/local/src/openresty-${OPENRESTY_VERSION}
#Configure Nginx with Optional Modules , You can Add or Remove your Desired Modules but mind the Dependencies
RUN ./configure --with-http_ssl_module \
--with-threads \
--with-http_secure_link_module \
--with-http_sub_module\
--with-luajit \
--with-openssl=/usr/local/src/openssl-3.2.0 \
--with-http_v2_module \
--with-http_dav_module \
--add-module=build/nginx-1.21.4/incubator-pagespeed-ngx-1.13.35.2-stable
RUN make -j8 && make install
#If you want , you can add luarocks and install some packages from it like autossl...
#for this purpose you can uncomment following lines
WORKDIR /usr/local/src/
ADD https://luarocks.org/releases/luarocks-3.9.2.tar.gz ./
RUN tar -xzvf luarocks-3.9.2.tar.gz
WORKDIR /usr/local/src/luarocks-3.9.2/
RUN ./configure --prefix=/usr/local/openresty/luajit \
--with-lua=/usr/local/openresty/luajit/ \
--lua-suffix=jit \
--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
RUN make -j8 && make install
#in the following line you can see how you can install luarocks package
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-auto-ssl
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-core
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-http
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-lrucache
RUN /usr/local/openresty/luajit/bin/luarocks install lua-cjson
RUN /usr/local/openresty/luajit/bin/luarocks install luasocket
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-t1k
# forward request and error logs to docker log collector
RUN mkdir -p /var/log/nginx && touch /var/log/nginx/access.log && touch /var/log/nginx/error.log
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
# create a docker-entrypoint.d directory
&& mkdir /docker-entrypoint.d
# Check install.
# RUN /usr/local/openresty/nginx/sbin/nginx -t
# RUN /usr/local/openresty/nginx/sbin/nginx -V
#Introduce Our Entrypoint for Running nginx on Container Startup
COPY ./entrypoint/docker-entrypoint.sh /
COPY ./entrypoint/10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
COPY ./entrypoint/20-envsubst-on-templates.sh /docker-entrypoint.d
COPY ./entrypoint/30-tune-worker-processes.sh /docker-entrypoint.d
ENV PATH=$PATH:/usr/local/openresty/nginx/sbin/
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 80 80
EXPOSE 443 443
STOPSIGNAL SIGQUIT
CMD ["nginx", "-g", "daemon off;"]
cd /usr/local/src/openresty-1.21.4.3/
nginx -V
-编译前
--prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.2 --add-module=../echo-nginx-module-0.63 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.33 --add-module=../ngx_lua-0.10.25 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.34 --add-module=../array-var-nginx-module-0.06 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../rds-json-nginx-module-0.16 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.13 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-http_ssl_module --with-threads --with-http_secure_link_module --with-http_sub_module --with-openssl=/usr/local/src/openssl-3.2.0 --with-http_v2_module --with-http_dav_module --add-module=/usr/local/src/openresty-1.21.4.3/build/nginx-1.21.4/incubator-pagespeed-ngx-1.13.35.2-stable --with-openssl-opt=-g --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module
-新编译,重新编译的代码和模块, 注意:千万别make install,否则就覆盖安装了
./configure --with-http_ssl_module --with-threads --with-http_secure_link_module --with-http_sub_module --with-openssl=/usr/local/src/openssl-3.2.0 --with-http_v2_module --with-http_dav_module --add-module=/usr/local/src/openresty-1.21.4.3/build/nginx-1.21.4/incubator-pagespeed-ngx-1.13.35.2-stable --with-openssl-opt=-g --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module --add-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/ngx_http_geoip2_module --with-stream --add-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/nginx-upsync --with-stream --add-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/ngx_brotli --add-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/nginx-dav-ext-module --add-dynamic-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/nginx-dav-ext-module --add-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/nginx-module-vts --add-dynamic-module=/data/site/htmltoo.f/htmltoo.soft/src/common/nginx-module/ngx_waf --with-cc-opt=-std=gnu99
--with-compat
make
sed -i 's/^\(CFLAGS.*\)/\1 -fstack-protector-strong -Wno-sign-compare/' objs/Makefile
make modules
cp objs/*.so /usr/local/nginx/modules
-最后在 nginx 的配置文件顶部添加一行
load_module "/usr/local/nginx/modules/ngx_http_waf_module.so";