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

Nginx 笔记_nginx最全教程

off999 2025-09-19 00:33 1 浏览 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

相关推荐

Linux 网络协议栈_linux网络协议栈

前言;更多学习资料(包含视频、技术学习路线图谱、文档等)后台私信《资料》免费领取技术点包含了C/C++,Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,Z...

揭秘 BPF map 前生今世_bpfdm

1.前言众所周知,map可用于内核BPF程序和用户应用程序之间实现双向的数据交换,为BPF技术中的重要基础数据结构。在BPF程序中可以通过声明structbpf_map_def...

教你简单 提取fmpeg 视频,音频,字幕 方法

ffmpeg提取视频,音频,字幕方法(HowtoExtractVideo,Audio,SubtitlefromOriginalVideo?)1.提取视频(ExtractVi...

Linux内核原理到代码详解《内核视频教程》

Linux内核原理-进程入门进程进程不仅仅是一段可执行程序的代码,通常进程还包括其他资源,比如打开的文件,挂起的信号,内核内部的数据结构,处理器状态,内存地址空间,或多个执行线程,存放全局变量的数据段...

Linux C Socket UDP编程详解及实例分享

1、UDP网络编程主要流程UDP协议的程序设计框架,客户端和服务器之间的差别在于服务器必须使用bind()函数来绑定侦听的本地UDP端口,而客户端则可以不进行绑定,直接发送到服务器地址的某个端口地址。...

libevent源码分析之bufferevent使用详解

libevent的bufferevent在event的基础上自己维护了一个buffer,这样的话,就不需要再自己管理一个buffer了。先看看structbufferevent这个结构体struct...

一次解决Linux内核内存泄漏实战全过程

什么是内存泄漏:程序向系统申请内存,使用完不需要之后,不释放内存还给系统回收,造成申请的内存被浪费.发现系统中内存使用量随着时间的流逝,消耗的越来越多,例如下图所示:接下来的排查思路是:1.监控系统中...

彻底搞清楚内存泄漏的原因,如何避免内存泄漏,如何定位内存泄漏

作为C/C++开发人员,内存泄漏是最容易遇到的问题之一,这是由C/C++语言的特性引起的。C/C++语言与其他语言不同,需要开发者去申请和释放内存,即需要开发者去管理内存,如果内存使用不当,就容易造成...

linux网络编程常见API详解_linux网络编程视频教程

Linux网络编程API函数初步剖析今天我们来分析一下前几篇博文中提到的网络编程中几个核心的API,探究一下当我们调用每个API时,内核中具体做了哪些准备和初始化工作。1、socket(family...

Linux下C++访问web—使用libcurl库调用http接口发送解析json数据

一、背景这两天由于一些原因研究了研究如何在客户端C++代码中调用web服务端接口,需要访问url,并传入json数据,拿到返回值,并解析。 现在的情形是远程服务端的接口参数和返回类型都是json的字符...

平衡感知调节:“系统如人” 视角下的架构设计与业务稳定之道

在今天这个到处都是数字化的时代,系统可不是一堆冷冰冰的代码。它就像一个活生生的“数字人”,没了它,业务根本转不起来。总说“技术要为业务服务”,但实际操作起来问题不少:系统怎么才能快速响应业务需求?...

谈谈分布式文件系统下的本地缓存_什么是分布式文件存储

在分布式文件系统中,为了提高系统的性能,常常会引入不同类型的缓存存储系统(算法优化所带来的的效果可能远远不如缓存带来的优化效果)。在软件中缓存存储系统一般可分为了两类:一、分布式缓存,例如:Memca...

进程间通信之信号量semaphore--linux内核剖析

什么是信号量信号量的使用主要是用来保护共享资源,使得资源在一个时刻只有一个进程(线程)所拥有。信号量的值为正的时候,说明它空闲。所测试的线程可以锁定而使用它。若为0,说明它被占用,测试的线程要进入睡眠...

Qt编写推流程序/支持webrtc265/从此不用再转码/打开新世界的大门

一、前言在推流领域,尤其是监控行业,现在主流设备基本上都是265格式的视频流,想要在网页上直接显示监控流,之前的方案是,要么转成hls,要么魔改支持265格式的flv,要么265转成264,如果要追求...

30 分钟搞定 SpringBoot 视频推拉流!实战避坑指南

30分钟搞定SpringBoot视频推拉流!实战避坑指南在音视频开发领域,SpringBoot凭借其快速开发特性,成为很多开发者实现视频推拉流功能的首选框架。但实际开发中,从环境搭建到流处理优...

取消回复欢迎 发表评论: