docker部署Nginx
docker部署nginx
拉取nginx鏡像
docker pull nginx:1.19.2
運行nginx
docker run --name nginx -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf:/etc/nginx/conf.d -d nginx:1.19.2
version: "3.2"
services:
nginx:
image: nginx:1.19.2
container_name: nginx
restart: always
ports:
- 80:80
volumes:
- /data/nginx/html:/usr/share/nginx/html
- /data/nginx/conf:/etc/nginx/conf.d
本地部署nginx
離線部署
官方下載安裝包
http://nginx.org/en/download.html
wget 或scp傳入/data/nginx目錄
解壓
tar -zxvf nginx-xxxx.tar.gz
進入解壓目錄。進行編譯安裝
安裝依賴
下載rpm包安裝即可
pcre,zlib,gcc,openssl
pcre-devel zlib-devel
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-stream
make && make install
Nginx升級
【備份配置文件】
cp -R /etc/nginx /tmp/nginx_old_config
【卸載原nginx】
service nginx stop
chkconfig nginx off
ps -ef | grep nginx
kill -9 {pid}
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
yum remove nginx
【解壓nginx】
cd /tmp
tar -zxvf nginx-1.15.12.tar.gz
cd nginx-1.15.12
【隱藏NGINX banner 和版本號】
修改源代碼/src/core/nginx.h
#define nginx_version 33333005010
#define NGINX_VERSION "888888888"
#define NGINX_VER "haha/" NGINX_VERSION
#define NGINX_VAR "AHAH"
--force --nodeps
【編譯】
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-stream
make && make install
【命令】
測試
nginx -t
啟動
nginx
停止
nginx -s stop
源碼安裝需要需要安裝:pcre,zlib,gcc,openssl
pcre-devel 的zlib-devel
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout cert.pem -out cert.pem -config req.conf -extensions 'v3_req'
生成ssl證書
openssl req -nodes -newkey rsa:1024 -out myreq.pem -keyout privatekey.pem
openssl req -in myreq.pem -x509 -key privatekey.pem -out mycert.pem -days 365
http://www.linuxe.cn/post-425.html
server {
listen 443 ssl;
server_name test.com;
keepalive_timeout 100; #開啟keepalive
ssl on;
ssl_certificate /usr/local/nginx/ssl/cert.pem; #指定數字證書文件
ssl_certificate_key /usr/local/nginx/ssl/cert.key; #指定數字證書私鑰文件
ssl_session_cache shared:SSL:10m; #緩存session會話
ssl_session_timeout 10m; #session 10分鍾過期
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}