<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="https://dwt.life/feed/rss/tag/nginx/">
<title>dwt&#039;s life - nginx</title>
<link>https://dwt.life/tag/nginx/</link>
<description></description>
<items>
<rdf:Seq>
<rdf:li resource="https://dwt.life/archives/334/"/>
<rdf:li resource="https://dwt.life/archives/137/"/>
<rdf:li resource="https://dwt.life/archives/67/"/>
<rdf:li resource="https://dwt.life/archives/12/"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="https://dwt.life/archives/334/">
<title>MacOS下的openresty编译过程</title>
<link>https://dwt.life/archives/334/</link>
<dc:date>2023-10-30T22:56:49+08:00</dc:date>
<description>其实还是比较简单的，毕竟homebrew已经很方便的安装了依赖，还是记录一下基本依赖我本地的brew是更新过了的，从github下载的最新releasebrew update                            
brew install pcre opensslconfigureLinux:./configure \                          
   --with-cc-opt=&quot;-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/&quot; \
   --with-ld-opt=&quot;-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/&quot; \
   -j8MacOS:./configure \                     
   --with-cc-opt=&quot;-I/opt/homebrew/include/openssl/ -I/opt/homebrew/include/&quot; \
   --with-ld-opt=&quot;-L/opt/homebrew/lib/&quot; \
   -j8这里的路径是我自己找的，brew应该都一样，但是看到别的文章和我的不一样，所以应该先检查include和lib的路径brotliBrotli比我当年编译的简单多了:git clone https://github.com/google/ngx_brotli.git`
cd ngx_brotli/deps/brotli
git clone https://github.com/google/brotli.git
cd ..
./configure \                      
   --with-cc-opt=&quot;-I/opt/homebrew/include/openssl/ -I/opt/homebrew/include/&quot; \
   --with-ld-opt=&quot;-L/opt/homebrew/lib/ --add-module=/路径/ngx_brotli&quot; \
   -j8然后make -j8 && make install 就到了/usr/local/openresty下了</description>
</item>
<item rdf:about="https://dwt.life/archives/137/">
<title>Nginx二级域名自动解析&amp;amp;伪静态&amp;amp;默认首页</title>
<link>https://dwt.life/archives/137/</link>
<dc:date>2021-10-03T22:32:00+08:00</dc:date>
<description>网站的目录结构为：# tree /home/wwwroot/application.pub
/home/wwwroot/application.pub
├── ai
│   └── index.html
└── file
    └── index.html/home/wwwroot/application.pub为nginx的安装目录下默认的存放源代码的路径。ai为博客程序源代码路径file为附件路径把相应程序放入上面的路径通过http://ai.application.pub 访问博客http://file.application.pub 访问附件其它二级域名类推。方法一：server {
listen 80;
server_name ~^(?&lt;subdomain&gt;.+).application.pub$;
access_log /data/wwwlogs/application.pub_nginx.log combined;
index index.html index.htm index.php;
root /home/wwwroot/application.pub/$subdomain/;
...
}方法二：server {
listen 80;
server_name *.application.pub;
access_log /home/wwwlogs/application.pub.log combined;
index index.html index.htm index.php;

if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
    set $subdomain $1;
    set $domain $2;
}

location / {
    root /home/wwwroot/application.pub/$subdomain/;
    index index.php $subdomain.html index.htm;
}

...
}</description>
</item>
<item rdf:about="https://dwt.life/archives/67/">
<title>Nginx /var/run/nginx.pid 问题：nginx: [error] invalid PID number</title>
<link>https://dwt.life/archives/67/</link>
<dc:date>2021-07-07T17:39:41+08:00</dc:date>
<description>根据检查，除了网上说的没有带上-c以外，还有一个情况，是/lib/service里面的nginx.service版本过旧导致的。reload=nginx -s reload即可。</description>
</item>
<item rdf:about="https://dwt.life/archives/12/">
<title>Nginx代理proxy pass配置去除前缀</title>
<link>https://dwt.life/archives/12/</link>
<dc:date>2021-06-29T16:45:00+08:00</dc:date>
<description>使用Nginx做代理的时候，可以简单的直接把请求原封不动的转发给下一个服务。比如，访问abc.com/appv2/a/b.html, 要求转发到localhost:8088/appv2/a/b.html简单配置如下：upstream one {
  server localhost:8088 weight=5;
}

server {
    listen              80;
    server_name         abc.com;
    access_log  &quot;pipe:rollback /data/log/nginx/access.log interval=1d baknum=7 maxsize=1G&quot;  main;

    location / {
        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_set_header X-NginX-Proxy true;

        proxy_pass http://one;
    }

}即，设置proxy_pass即可。请求只会替换域名。但很多时候，我们需要根据url的前缀转发到不同的服务。比如abc.com/user/profile.html转发到 用户服务localhost:8089/profile.htmlabc.com/order/details.html转发到 订单服务 localhost:8090/details.html即，url的前缀对下游的服务是不需要的，除非下游服务添加context-path, 但很多时候我们并不喜欢加这个。如果Nginx转发的时候，把这个前缀去掉就好了。一个种方案是proxy_pass后面加根路径/.server {
    listen              80;
    server_name         abc.com;
    access_log  &quot;pipe:rollback /data/log/nginx/access.log interval=1d baknum=7 maxsize=1G&quot;  main;

    location ^~/user/ {
        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_set_header X-NginX-Proxy true;

        proxy_pass http://user/;
    }

    location ^~/order/ {
        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_set_header X-NginX-Proxy true;

        proxy_pass http://order/;
    }

}^~/user/表示匹配前缀是user的请求，proxy_pass的结尾有/， 则会把/user/*后面的路径直接拼接到后面，即移除user.另一种方案是使用rewriteupstream user {
  server localhost:8089 weight=5;
}
upstream order {
  server localhost:8090 weight=5;
}


server {
    listen              80;
    server_name         abc.com;
    access_log  &quot;pipe:rollback /data/log/nginx/access.log interval=1d baknum=7 maxsize=1G&quot;  main;

    location ^~/user/ {
        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_set_header X-NginX-Proxy true;

        rewrite ^/user/(.*)$ /$1 break;
        proxy_pass http://user;
    }

    location ^~/order/ {
        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_set_header X-NginX-Proxy true;

        rewrite ^/order/(.*)$ /$1 break;
        proxy_pass http://order;
    }

}注意到proxy_pass结尾没有/， rewrite重写了url。关于rewritesyntax: rewrite regex replacement [flag]
Default: —
Context: server, location, if</description>
</item>
</rdf:RDF>