百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

Nginx 笔记_nginx最全教程

off999 2025-09-19 00:33 25 浏览 0 评论

gcc

# 可能需要安装C++
yum -y install gcc-c++

install nginx by bash


cd /usr/local/src

#
# @see http://nginx.org/en/download.html
#
wget http://nginx.org/download/nginx-1.15.11.tar.gz

tar -xzvf nginx-1.15.11.tar.gz

#
# @see http://www.pcre.org/
#
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

tar -xzvf pcre-8.43.tar.gz

#
# @see https://www.openssl.org/source/
#
wget https://www.openssl.org/source/openssl-1.0.2r.tar.gz

tar -xzvf openssl-1.0.2r.tar.gz

#
# @see http://www.zlib.net/
#
wget http://www.zlib.net/zlib-1.2.11.tar.gz

tar -xzvf zlib-1.2.11.tar.gz


# 重点来了!!!
cd nginx-1.15.11

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.43 \
--with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2r

make && make install

test -e /usr/bin/nginx || ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

install nginx by bash with versioning

cd /usr/local/src

nginx_version=1.16.1
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11

#
# @see http://nginx.org/en/download.html
#
wget http://nginx.org/download/nginx-${nginx_version}.tar.gz

tar -xzvf nginx-${nginx_version}.tar.gz

#
# @see http://www.pcre.org/
#
wget https://ftp.pcre.org/pub/pcre/pcre-${pcre_version}.tar.gz

tar -xzvf pcre-${pcre_version}.tar.gz

#
# @see https://www.openssl.org/source/
#
wget https://www.openssl.org/source/openssl-${openssl_version}.tar.gz

tar -xzvf openssl-${openssl_version}.tar.gz

#
# @see http://www.zlib.net/
#
wget http://www.zlib.net/zlib-${zlib_version}.tar.gz

tar -xzvf zlib-${zlib_version}.tar.gz


# 重点来了!!!
cd nginx-${nginx_version}

./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre=../pcre-${pcre_version} \
--with-zlib=../zlib-${zlib_version} \
--with-openssl=../openssl-${openssl_version}

make && make install

test -e /usr/bin/nginx || ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
# nginx user
# useradd -M -s /sbin/nologin nginx

install nginx with lua

结论:直接使用 OpenResty[1]

lua-nginx-module[2]

dynamic-nginx-upstreams-with-lua-and-redis[3]

installation[4]


########################### Download ###########################

wget -O "luajit2-v2.1-20200102.tar.gz" https://github.com/openresty/luajit2/archive/v2.1-20200102.tar.gz

wget -O "ngx_devel_kit-v0.3.1.tar.gz" https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz

wget -O "lua-nginx-module-v0.10.17.tar.gz" https://github.com/openresty/lua-nginx-module/archive/v0.10.17.tar.gz

nginx_version=1.17.8
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11

#
# @see http://nginx.org/en/download.html
#
wget http://nginx.org/download/nginx-${nginx_version}.tar.gz

tar -xzvf nginx-${nginx_version}.tar.gz

#
# @see http://www.pcre.org/
#
wget https://ftp.pcre.org/pub/pcre/pcre-${pcre_version}.tar.gz

tar -xzvf pcre-${pcre_version}.tar.gz

#
# @see https://www.openssl.org/source/
#
wget https://www.openssl.org/source/openssl-${openssl_version}.tar.gz

tar -xzvf openssl-${openssl_version}.tar.gz

#
# @see http://www.zlib.net/
#
wget http://www.zlib.net/zlib-${zlib_version}.tar.gz

tar -xzvf zlib-${zlib_version}.tar.gz
########################### 安装 LuaJIT ###########################
cd luajit2-v2.1-20200102
make install PREFIX=/usr/local/LuaJIT
###
########################### make-nginx.sh ###########################

nginx_version=1.17.8
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11

# 重点来了!!!
cd nginx-${nginx_version}


# tell nginx's build system where to find LuaJIT 2.1:
export LUAJIT_LIB=/usr/local/LuaJIT/lib
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.1

./configure --prefix=/usr/local/nginx \
--with-ld-opt="-Wl,-rpath,/usr/local/LuaJIT/lib" \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre=../pcre-${pcre_version} \
--with-zlib=../zlib-${zlib_version} \
--with-openssl=../openssl-${openssl_version} \
--add-module=../ngx_devel_kit-0.3.1 \
--add-module=../lua-nginx-module-0.10.17

make
########################### install-nginx.sh ###########################
nginx_version=1.17.8
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11

# 重点来了!!!
cd nginx-${nginx_version}

make install
########################### 最后的最后 ###########################

# 启动 nginx 出错:

#nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an #OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
# no field package.preload['resty.core']
# no file './resty/core.lua'
# no file '/usr/local/LuaJIT/share/luajit-2.1.0-beta3/resty/core.lua'
# no file '/usr/local/share/lua/5.1/resty/core.lua'
# no file '/usr/local/share/lua/5.1/resty/core/init.lua'
# no file '/usr/local/LuaJIT/share/lua/5.1/resty/core.lua'
# no file '/usr/local/LuaJIT/share/lua/5.1/resty/core/init.lua'
# no file './resty/core.so'
# no file '/usr/local/lib/lua/5.1/resty/core.so'
# no file '/usr/local/LuaJIT/lib/lua/5.1/resty/core.so'
# no file '/usr/local/lib/lua/5.1/loadall.so'
# no file './resty.so'
# no file '/usr/local/lib/lua/5.1/resty.so'
# no file '/usr/local/LuaJIT/lib/lua/5.1/resty.so'
# no file '/usr/local/lib/lua/5.1/loadall.so') in /usr/local/nginx/conf/nginx.conf:121

# 根据上面的错误提示下载下面的包
wget https://openresty.org/download/openresty-1.17.8.1.tar.gz

# 复制 lua-resty-core-0.1.19 及 lua-resty-lrucache-0.10 中的库到 /usr/local/LuaJIT/share/lua/5.1/

install nginx with njs

Building from the sources[5]

njs_version=0.4.1
wget -O "njs-${njs_version}.tar.gz" http://hg.nginx.org/njs/archive/${njs_version}.tar.gz
tar -xzvf njs-${njs_version}.tar.gz
########################### make-nginx.sh ###########################
nginx_version=1.16.1
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11
njs_version=0.4.1

# 重点来了!!!
cd nginx-${nginx_version}

./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre=../pcre-${pcre_version} \
--with-zlib=../zlib-${zlib_version} \
--with-openssl=../openssl-${openssl_version} \
--add-dynamic-module=../njs-${njs_version}/nginx

make
########################### install-nginx.sh ###########################
nginx_version=1.16.1
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11

# 重点来了!!!
cd nginx-${nginx_version}

make install

install nginx with stream

########################### make-stream-nginx.sh ###########################
nginx_version=1.21.1
pcre_version=8.43
openssl_version=1.1.1d
zlib_version=1.2.11

# 重点来了!!!
cd nginx-${nginx_version}

./configure --prefix=/usr/local/stream_nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-openssl-opt=enable-weak-ssl-ciphers \
--with-pcre=../pcre-${pcre_version} \
--with-zlib=../zlib-${zlib_version} \
--with-openssl=../openssl-${openssl_version} \
--with-stream \
--with-stream_ssl_module

make

sftp

假定出口 ip 固定为 192.168.1.2,则可以利用 Nginx Stream 进行代理。

stream {
    upstream sftp-01 {
        server 192.168.1.100:22;
    }
    upstream sftp-02 {
        server 192.168.1.101:22;
    }
    server {
        listen 10508;
        proxy_bind 192.168.1.2;
        proxy_pass sftp-01;
    }
    server {
        listen 10509;
        proxy_bind 192.168.1.2;
        proxy_pass sftp-02;
    }
}

start nginx

# 开启端口(permanent永久)
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent

# 重启firewall生效
firewall-cmd --reload
# 查看开启的端口
firewall-cmd --list-ports

# 符号链接
test -e /usr/bin/nginx || ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

# start
nginx

nginx systemd service file

nginx systemd service file[6]

The location of the PIDFile and the NGINX binary may be different depending on how NGINX was compiled.

Save this file as /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# 开机启动
systemctl enable nginx

# 立即启动
systemctl start nginx

add module

以--with-stream=dynamic为例,--add-module类似

#
# 查看nginx详细安装信息
#
nginx -V
# nginx version: nginx/1.15.11
# built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
# built with OpenSSL 1.0.2r  26 Feb 2019
# TLS SNI support enabled
# configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module \
# --with-http_gzip_static_module --with-http_stub_status_module \
# --with-pcre=../pcre-8.43 --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.0.2r

#
# whereis nginx 查看本机是否存在nginx源码目录
# 若没有,下载对应版本的源,如nginx
# cd /usr/local/src
# nginx_version=1.15.11
# wget http://nginx.org/download/nginx-${nginx_version}.tar.gz
#

cd /usr/local/src/nginx-1.15.11
# 将配置输出到ngx_config.sh
nginx -V 2>&1 | awk '{print $0}' > ngx_config.sh

# --with-stream=dynamic
vim ngx_config.sh
#./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module \
# --with-http_gzip_static_module --with-http_stub_status_module \
# --with-pcre=../pcre-8.43 --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.0.2r --with-stream=dynamic

chmod 755 ngx_config.sh

bash ngx_config.sh

# 只执行make
make

# copy
cp /usr/local/nginx/sbin/nginx{,.bak}
cp ./objs/nginx /usr/local/nginx/sbin/
cp ./objs/ngx_stream_module.so /usr/local/nginx/modules/

# 编辑nginx.conf
vim /usr/local/nginx/conf/nginx.conf
# 顶层添加如下指令
# load_module modules/ngx_stream_module.so;

# 重新加载配置
nginx -s reload

clean nginx log

# pwd
cd /usr/local/nginx

clean script

vim clean_access_log.sh
#! /bin/bash

NGINX_LOG_DIR="/usr/local/nginx/logs"

cat /dev/null > ${NGINX_LOG_DIR}/access.log
cat /dev/null > ${NGINX_LOG_DIR}/company.access.log
cat /dev/null > ${NGINX_LOG_DIR}/show.access.log
cat /dev/null > ${NGINX_LOG_DIR}/api.access.log
#echo $(date '+%F %T') >> ${NGINX_LOG_DIR}/crontab.log
chmod 755 clean_access_log.sh

crontab


# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

# cron service
systemctl status crond

crontab -e
# 每天凌晨3点清理
0 3 * * * /usr/local/nginx/clean_access_log.sh

# 每隔30分钟
*/30 * * * * /usr/local/nginx/clean_access_log.sh
# 查看定时任务
crontab -l

# 重启生效
systemctl reload crond

configuration

proxy_cache

ngx_http_proxy_module[7]

nginx proxy_cache 缓存配置[8]

http {
    include 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" '
    '$request_time $upstream_response_time $upstream_addr $upstream_cache_status';

    access_log logs/access.log main;

    sendfile on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout 65;
    resolver 223.5.5.5 114.114.114.114 8.8.8.8;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types application/json text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;

    # step 1: 配置 cache path
    proxy_cache_path /usr/local/nginx/proxy_cache levels=1:2 keys_zone=static-cache:1024m max_size=100g inactive=30d;

    js_import js/http.js;
    js_set $summary http.summary;

    upstream city-w-sites {
        ip_hash;

        server 192.168.1.68;
        server 192.168.1.69;
        server 192.168.1.120;
    }
    server {
        listen 80;
        server_name localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            #proxy_set_header X-Real-IP $http_x_real_ip;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_read_timeout 300;
            proxy_pass http://city-w-sites;
        }
        location ~* \.(gif|jpg|jpeg|png|bmp|swf|svg|woff|woff2|eot|ttf|js|css)$ {
            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_read_timeout 300;
            proxy_pass http://city-w-sites;
            # step 2: 配置 proxy cache
            proxy_cache static-cache;
            proxy_cache_key $scheme$proxy_host$request_uri;
            proxy_cache_valid 200 206 304 301 302 10d;
        }
        location = /summary {
            default_type text/plain;
            return 200 $summary;
        }
        location = /hello {
            default_type text/plain;
            js_content http.hello;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }

learn nginx

Beginner’s Guide[9]

Starting, Stopping, and Reloading Configuration

To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:

nginx -s signal

Where signal may be one of the following:

  • stop — fast shutdown
  • quit — graceful shutdown
  • reload — reloading the configuration file
  • reopen — reopening the log files

For example, to stop nginx processes with waiting for the worker processes to finish serving current requests, the following command can be executed:

nginx -s quit

This command should be executed under the same user that started nginx. Changes made in the configuration file will not be applied until the command to reload configuration is sent to nginx or it is restarted. To reload configuration, execute:

nginx -s reload

Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit.

Resource

nginx location 中 uri 的截取[10]

关于一些对 location 认识的误区[11]

nginx 常用模块整理[12]

zabbix ZBX_NGINX[13]

如何监控 NGINX[14]

SSL under IE8/Windows XP with NGINX and OpenSSL[15]

nginx.conf

  • ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";

compile

  • --with-openssl-opt=enable-weak-ssl-ciphers

agentzh 的 Nginx 教程[16]

imageproxy[17] A caching, resizing image proxy written in Go.

  • nginx cache + imageproxy + minio 支持多级 cache 的图片缩放处理服务[18]

负载均衡[19]

zabbix

ZBX_NGINX[20]

docker

docker hub[21]

# nginx
mkdir /usr/local/nginx
# conf
mkdir /usr/local/nginx/conf
# logs
mkdir /usr/local/nginx/logs
# html
mkdir /usr/local/nginx/html
# vim /usr/local/nginx/conf/nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

配置文件中相对路径由 build 时确定,查看Building nginx from Sources[22]

docker run -d --name nginx7 \
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/nginx/logs:/etc/nginx/logs \
-v /usr/local/nginx/html:/etc/nginx/html \
-p 80:80 -p 443:443 \
nginx:1.17.9

mynginx

根据 showdoc[23] 的 Dockerfile

FROM richarvey/nginx-php-fpm:1.5.3
COPY ./ /var/www/html/

RUN apk update
RUN apk add openldap-dev
RUN docker-php-ext-install ldap

RUN chmod -R 777 /var/www/html/
RUN mkdir /showdoc_data
RUN mkdir /showdoc_data/html
RUN cp -R /var/www/html/ /showdoc_data/
CMD if [ ! -f "/var/www/html/index.php" ]; then \cp -fr /showdoc_data/html/ /var/www/ ;fi;chmod 777 -R /showdoc_data ;/start.sh

定制自己的 nginx Dockerfile,启动命令 CMD 可将容器内的复制文件复制到主机上

FROM nginx:1.17.9

RUN mkdir -p /tmp/nginx/conf

RUN cp -R /etc/nginx/* /tmp/nginx/conf

CMD if [ ! -f "/etc/nginx/nginx.conf" ]; then \cp -fr /tmp/nginx/conf/* /etc/nginx/;fi;chmod 777 -R /etc/nginx/; nginx -g 'daemon off;';

usage


# nginx 数据目录

mkdir /root/nginx/

# 注意 -v
docker run -d --name mynginx -v /root/nginx/conf:/etc/nginx/ -v /root/nginx/logs:/etc/nginx/logs -v /root/nginx/html:/etc/nginx/html -p 82:80 ringliwei/nginx:v1.3

nginx 配置文件(配置文件中相对路径由 build 时确定,查看Building nginx from Sources[24]

user  nginx;
worker_processes  1;

error_log  logs/error.log warn;
pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    # this is a moment
    include conf.d/*.conf;
}

nginx-proxy

  • nginx-proxy[25] Automated nginx proxy for Docker containers using docker-gen.
  • Automated Nginx Reverse Proxy for Docker[26]
  • jwilder/nginx-proxy[27]

CORS

location / {
    if ($request_method = 'OPTIONS') {
        add_header Access-Control-Allow-Origin '$http_origin';
        add_header Access-Control-Allow-Credentials 'true';
        add_header Access-Control-Allow-Methods '$http_access_control_request_method';
        add_header Access-Control-Allow-Headers '$http_access_control_request_headers';
        add_header Access-Control-Max-Age '2592000';
        # OPTIONS
        return 204;
    }
    add_header Access-Control-Allow-Origin '$http_origin';
    add_header Access-Control-Allow-Credentials 'true';
    proxy_pass http://web;
}

Problem

  • 在 nginx 1.12.2 版本配置 upstream 时, 可以使用 upstream backend_service 这样的名称(包含下划线)来命名,但 nginx 1.16.1 命名 upstream 时由不能带下划线
  • nginx proxy_pass to https[28] proxy_ssl_server_name on

引用链接

  • [1] OpenResty: https://openresty.org/en/
  • [2] lua-nginx-module: https://github.com/openresty/lua-nginx-module
  • [3] dynamic-nginx-upstreams-with-lua-and-redis: https://sosedoff.com/2012/06/11/dynamic-nginx-upstreams-with-lua-and-redis.html
  • [4] installation: https://github.com/openresty/lua-nginx-module#installation
  • [5] Building from the sources: http://nginx.org/en/docs/njs/install.html
  • [6] nginx systemd service file: https://www.nginx.com/resources/wiki/start/topics/examples/systemd/
  • [7] ngx_http_proxy_module: http://nginx.org/en/docs/http/ngx_http_proxy_module.html
  • [8] nginx proxy_cache 缓存配置: https://blog.csdn.net/ai2000ai/article/details/80485352
  • [9] Beginner’s Guide: http://nginx.org/en/docs/beginners_guide.html
  • [10] nginx location 中 uri 的截取: https://www.jianshu.com/p/849a6c068daa
  • [11] 关于一些对 location 认识的误区: https://www.cnblogs.com/lidabo/p/4169396.html
  • [12] nginx 常用模块整理: https://www.cnblogs.com/fangfei9258/p/9453709.html
  • [13] zabbix ZBX_NGINX: https://github.com/AlexGluck/ZBX_NGINX
  • [14] 如何监控 NGINX: https://linux.cn/article-5970-1.html
  • [15] SSL under IE8/Windows XP with NGINX and OpenSSL: https://ablagoev.github.io/ssl/nginx/ie8/winxp/cipher/2016/12/23/ie8-winxp-nginx-ssl.html
  • [16] agentzh 的 Nginx 教程: https://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
  • [17] imageproxy: https://github.com/willnorris/imageproxy
  • [18] nginx cache + imageproxy + minio 支持多级 cache 的图片缩放处理服务: https://www.cnblogs.com/rongfengliang/p/13922297.html
  • [19] 负载均衡: https://mp.weixin.qq.com/s/8y6IxIM8ApXakVjn8rx9aw
  • [20] ZBX_NGINX: https://github.com/AlexGluck/ZBX_NGINX
  • [21] docker hub: https://hub.docker.com/_/nginx
  • [22] Building nginx from Sources: http://nginx.org/en/docs/configure.html
  • [23] showdoc: https://hub.docker.com/r/star7th/showdoc/dockerfile
  • [24] Building nginx from Sources: http://nginx.org/en/docs/configure.html
  • [25] nginx-proxy: https://github.com/nginx-proxy/nginx-proxy
  • [26] Automated Nginx Reverse Proxy for Docker: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/
  • [27] jwilder/nginx-proxy: https://hub.docker.com/r/jwilder/nginx-proxy
  • [28] nginx proxy_pass to https: https://serverfault.com/questions/978922/nginx-proxy-pass-to-https

相关推荐

浏览器最好用的(浏览器最好用的插件)

一、谷歌浏览器谷歌浏览器是公认最好用的,这个可以从市场占有率看出端倪,超过三分之二的用户使用谷歌浏览器。Chrome浏览器以简洁快速著称,不管是普通用户还是开发人员,chrome浏览器都是首选。Chr...

fast路由器6位初始密码(fast路由器的密码)

答:fast路由器初始密码是admin;新款的迅捷无线路由器,管理界面没有初始密码。查看迅捷无线路由器底部标签,标签上标注了admin,说明初始密码就是admin;如果没有,说明该路由器没有初始密码。...

硬盘恢复软件哪个好(硬盘 恢复软件)

迷你兔数据恢复工具:支持恢复硬盘丢失的数据Pc3000数据恢复软件是一款非常专业的硬盘修复工具,能够对电脑硬盘资料数据进行修复,通过使用这个软件可以解决硬盘数据丢失故障,是一个用户进行硬盘资料修复好帮...

十大品牌监控摄像头排名(十大品牌监控摄像头排名第一)

答:1、华为/HUAWEI9.92、小米/MI9.63、罗技/Logitech9.64、海康威视/HIKVISION9.25、乔安/Jooan9.26、普联/TP-LINK9.27、乐橙8.98、萤石...

360手机助手老旧版本大全(360手机助手 老版本)

在设置里面找到历史记录就可能查看360手机助手·换机神器是安卓系统的换机软件,因为苹果的换机软件是爱思。1、打开360手机卫士,登陆账号,点击账号。2、进入个人中心,点击账户安全,在密保工具中,点击解...

系统应用工程师(系统工程的应用)

信息软件系统工程师有前途,毕业以后可以从事软件开发,软件系统的维护,运营等等,和计算机有关的工作内容,因为计算机专业可以说是一个非常热门的专业,很多的大型企业公司基本上都是以计算机研发为主的,薪资福利...

qq恢复系统常见问题(qq恢复系统常见问题及答案)

QQ好友恢复系统一直显示服务器频繁有可能是系统的问题,你的qq重新更新一下,或者你卸载了重新下载一下就有可能好了。您好,很高兴为您解答:您可以试试清空下IE内存,然后关掉不必要的程序,尽量在电脑运...

win10自带的office不见了(win10自带的office在哪个文件夹)

win10系统的office在电脑硬盘office的安装目录里,具体打开安装目录的操作如下:1、首先我们右键点击word,打开方式,选择默认程序打开。2、在默认框打钩,点击【浏览】。3、打开你安装of...

华为官网序列号查询入口(华为官网序列号查询入口手写笔)
  • 华为官网序列号查询入口(华为官网序列号查询入口手写笔)
  • 华为官网序列号查询入口(华为官网序列号查询入口手写笔)
  • 华为官网序列号查询入口(华为官网序列号查询入口手写笔)
  • 华为官网序列号查询入口(华为官网序列号查询入口手写笔)
手机主题美化包(手机主题美化包下载)
  • 手机主题美化包(手机主题美化包下载)
  • 手机主题美化包(手机主题美化包下载)
  • 手机主题美化包(手机主题美化包下载)
  • 手机主题美化包(手机主题美化包下载)
w10系统我的电脑在哪里(windows10 我的电脑在哪)

首先,打开Windows10系统,可以看到当前桌面上没有“我的电脑”。二、然后,在桌面上鼠标右键都加空白处,在右键菜单中选择“个性化”,点击打开。三、然后,在窗口中左侧选择“更改桌面图标”,点击打开。...

2500电脑组装最强配置(2500左右组装电脑主机配置清单)

两千五百元组装电脑,但配置只能是一般。台式机分为主机和显示器两个主体,按这个价格,显示器只能配置一般的,大约两百多元价格,其余都用来组装主机,主机包含机箱,电源,排风扇,电脑主板及内存,电脑处理器,声...

小米手机定时关机怎么设置(如何让小米手机定时关机)
小米手机定时关机怎么设置(如何让小米手机定时关机)

1、从设置菜单中找到电池与性能选项。      2、选择电池版块,点击定时开关机。      3、将定时开机右边的按钮开...

2025-12-28 02:51 off999

磁盘删除的文件怎么恢复(磁盘误删怎么恢复)

可以恢复,因为删除文件时,其实只是把表头删除了,后面的数据并没有删除,直到下一次进行写磁盘操作需要占用节点所在位置时,才会把相应的数据覆盖掉。所以,就算你误删了文件之后又进行了其他写磁盘操作,只要没有...

qq自动回复内容古风(qq自动回复古文)
qq自动回复内容古风(qq自动回复古文)

1、抽剑相助,搭救无辜,却引来杀身之祸。那女子故作柔弱,假装爱慕,只为那本剑谱。2、只缘感君一回顾,使我思君朝与暮。3、相知相惜若可谓缘,不负韶华年。4、看那天地日月,恒静无言;青山长河,世代绵延;就像在我心中,你从未离去,也从未改变。5、...

2025-12-28 01:51 off999

取消回复欢迎 发表评论: