nginx 服务器初始化

Last updated on November 22, 2024 pm

🧙 Questions

使用docker安装nginx,并将nginx作为唯一出口代理

☄️ Ideas

docker run -v /Users/ispong/Isxcode/spark-yun/docs/:/usr/share/nginx/html/ -v /Users/ispong/Isxcode/spark-yun/docs/nginx.conf:/etc/nginx/conf.d/default.conf  -p 30122:80 -d nginx
配置ssl代理
mkdir -p /data/nginx/ssl
cd /data/nginx/ssl
scp ~/Downloads/8070478_ispong.isxcode.com_nginx.zip root@isxcode.com:/data/nginx/ssl/
unzip /data/nginx/ssl/8070478_ispong.isxcode.com_nginx.zip
初始化nginx.conf文件
mkdir -p /data/nginx/conf
vim /data/nginx/conf/default.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

# ------------------------------ blogs-galaxy ------------------------------
server {
    listen             80;
    listen             [::]:80;
    server_name        ispong.isxcode.com;
    rewrite ^(.*)$ https://${server_name}$1 permanent; # 支持history,防止页面无法访问
}

server {
    listen              443 ssl http2;
    listen              [::]:443 ssl http2;
    server_name         ispong.isxcode.com;

    ssl_certificate           "/data/nginx/ssl/8070478_ispong.isxcode.com.pem";
    ssl_certificate_key       "/data/nginx/ssl/8070478_ispong.isxcode.com.key";
    ssl_session_cache         shared:SSL:1m;
    ssl_session_timeout       10m;
    ssl_ciphers               HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;

    location / {
        proxy_pass http://172.24.28.255:30203;
    }

    location = /robots.txt {
        alias /data/nginx/ssl/robots.txt;
    }

    error_page 404 /404.html;
    location = /40x.html {

    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {

    }
}

# ============ gzip ===============
# 是否开启gzip,默认关闭off
gzip            on;
# 32 4k|16 8k 设置压缩单位
gzip_buffers    32 4k;
# 压缩级别,等级越大,压缩时间越长
gzip_comp_level 6;
# 正则匹配哪些浏览器不需要压缩
gzip_disable    "MSIE [1-6]\.";
# 配置http版本,满足1.1即实行压缩
gzip_http_version 1.1;
# 文件最小长度,即不需要压缩
gzip_min_length   20;
# 是否压缩代理的数据
gzip_proxied      off;
# 匹配哪些文件需要压缩
gzip_types        application/javascript text/css text/xml;
# 判断浏览器是否支持压缩
gzip_vary         on;
启动nginx
docker run \
  --name main-nginx \
  --privileged=true \
  --restart=always \
  -d \
  -p 80:80 \
  -p 443:443 \
  -v /data/nginx/conf:/etc/nginx/conf.d \
  -v /data/nginx/ssl:/data/nginx/ssl \
  nginx

nginx 服务器初始化
https://ispong.isxcode.com/vue/nginx/nginx 服务器初始化/
Author
ispong
Posted on
March 10, 2023
Licensed under