diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..abe8b76 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +ko_fi: jaywcjlove +buy_me_a_coffee: jaywcjlove +custom: ["https://www.paypal.me/kennyiseeyou", "https://jaywcjlove.github.io/#/sponsor"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e136fdb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: CI +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: 'https://registry.npmjs.org' + + - run: npm install + - run: npm run build + + - name: Generate Contributors Images + uses: jaywcjlove/github-action-contributors@main + with: + filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\]) + output: dist/CONTRIBUTORS.svg + avatarSize: 42 + + - name: Create Tag + id: create_tag + uses: jaywcjlove/create-tag-action@main + with: + package-path: ./package.json + + - name: Deploy Website + uses: peaceiris/actions-gh-pages@v4 + with: + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' + commit_message: ${{ github.event.head_commit.message }} + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./dist + + - name: Generate Changelog + id: changelog + uses: jaywcjlove/changelog-generator@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + filter-author: (jaywcjlove|小弟调调™|dependabot\[bot\]|Renovate Bot) + filter: (^[\s]+?[R|r]elease)|(^[R|r]elease) + + - name: Create Release + uses: ncipollo/release-action@v1 + if: steps.create_tag.outputs.successful + with: + allowUpdates: true + token: ${{ secrets.GITHUB_TOKEN }} + name: ${{ steps.create_tag.outputs.version }} + tag: ${{ steps.create_tag.outputs.version }} + body: | + [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) + + Documentation ${{ steps.changelog.outputs.tag }}: https://raw.githack.com/jaywcjlove/vim-web/${{ steps.changelog.outputs.gh-pages-short-hash }}/index.html + Comparing Changes: ${{ steps.changelog.outputs.compareurl }} + + ${{ steps.changelog.outputs.changelog }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a093f12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +lib +dist +node_modules +coverage +test/out + +npm-debug.log* +lerna-debug.log +yarn-error.log +package-lock.json + +.DS_Store +.cache +.vscode +.idea + +*.bak +*.tem +*.temp +#.swp +*.*~ +~*.* + +# IDEA +*.iml +*.ipr +*.iws +.idea/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..64e05d5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 小弟调调™ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index b1e5454..95fe32c 100755 --- a/README.md +++ b/README.md @@ -1,25 +1,33 @@ -

- + +

+ + +

Nginx 入门学习笔记

+ + +[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) -Nginx 是一款面向性能设计的 HTTP 服务器,能反向代理 HTTP,HTTPS 和邮件相关(SMTP,POP3,IMAP)的协议链接。并且提供了负载均衡以及 HTTP 缓存。它的设计充分使用异步事件模型,削减上下文调度的开销,提高服务器并发能力。采用了模块化设计,提供了丰富模块的第三方模块。 +[Nginx](https://nginx.org/en/) 是一款面向性能设计的 HTTP 服务器,能反向代理 HTTP、HTTPS 和邮件相关(SMTP、POP3、IMAP)的协议链接,并且提供了负载均衡以及 HTTP 缓存。它的设计充分使用异步事件模型,削减上下文调度的开销,提高服务器并发能力。采用了模块化设计,提供了丰富的第三方模块。 -所以关于 Nginx,有这些标签:「异步」「事件」「模块化」「高性能」「高并发」「反向代理」「负载均衡」 +关于 Nginx,有这些标签:「异步」「事件」「模块化」「高性能」「高并发」「反向代理」「负载均衡」 -Linux系统:`Centos 7 x64` +Linux系统:`Centos 7 x64` Nginx版本:`1.11.5` -目录 -=== + + +## 目录 + - [安装](#安装) - [安装依赖](#安装依赖) - [下载](#下载) - [编译安装](#编译安装) - - [nginx测试](#nginx测试) - - [设置全局nginx命令](#设置全局nginx命令) + - [Nginx 测试](#nginx-测试) + - [设置全局 nginx 命令](#设置全局-nginx-命令) - [Mac 安装](#mac-安装) - [安装nginx](#安装nginx) - [启动服务](#启动服务) @@ -27,7 +35,7 @@ Nginx版本:`1.11.5` - [运维](#运维) - [服务管理](#服务管理) - [重启服务防火墙报错解决](#重启服务防火墙报错解决) -- [nginx卸载](#nginx卸载) +- [Nginx 卸载](#nginx-卸载) - [参数说明](#参数说明) - [配置](#配置) - [常用正则](#常用正则) @@ -61,7 +69,7 @@ Nginx版本:`1.11.5` - [代理转发](#代理转发) - [监控状态信息](#监控状态信息) - [代理转发连接替换](#代理转发连接替换) - - [ssl配置](#ssl配置) + - [SSL 配置](#ssl-配置) - [强制将http重定向到https](#强制将http重定向到https) - [两个虚拟主机](#两个虚拟主机) - [虚拟主机标准配置](#虚拟主机标准配置) @@ -71,14 +79,17 @@ Nginx版本:`1.11.5` - [防盗图配置](#防盗图配置) - [屏蔽.git等文件](#屏蔽git等文件) - [域名路径加不加需要都能正常访问](#域名路径加不加需要都能正常访问) + - [cockpit](#cockpit) - [错误问题](#错误问题) - [精品文章参考](#精品文章参考) + + ## 安装 ### 安装依赖 -> prce(重定向支持)和openssl(https支持,如果不需要https可以不安装。) +> prce(重定向支持)和 openssl(https 支持,如果不需要 https 可以不安装)。 ```bash yum install -y pcre-devel @@ -86,18 +97,17 @@ yum -y install gcc make gcc-c++ wget yum -y install openssl openssl-devel ``` -CentOS 6.5 我安装的时候是选择的“基本服务器”,默认这两个包都没安装全,所以这两个都运行安装即可。 +在 CentOS 6.5 上安装时,我选择了“基本服务器”,默认情况下这两个包都没有安装全,所以需要运行上述命令进行安装。 ### 下载 -[nginx的所有版本在这里](http://nginx.org/download/) +[nginx 的所有版本在这里](http://nginx.org/download/) ```bash wget http://nginx.org/download/nginx-1.13.3.tar.gz wget http://nginx.org/download/nginx-1.13.7.tar.gz -# 如果没有安装wget -# 下载已编译版本 +# 如果没有安装 wget $ yum install wget # 解压压缩包 @@ -142,7 +152,7 @@ make make install ``` -### nginx测试 +### Nginx 测试 运行下面命令会出现两个结果,一般情况nginx会安装在`/usr/local/nginx`目录中 @@ -154,7 +164,7 @@ cd /usr/local/nginx/sbin/ # nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful ``` -### 设置全局nginx命令 +### 设置全局 Nginx 命令 ```bash vi ~/.bash_profile @@ -303,13 +313,13 @@ Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service t ```bash systemctl is-enabled servicename.service # 查询服务是否开机启动 -systemctl enable *.service # 开机运行服务 +systemctl enable *.service # 开机运行服务 systemctl disable *.service # 取消开机运行 -systemctl start *.service # 启动服务 -systemctl stop *.service # 停止服务 +systemctl start *.service # 启动服务 +systemctl stop *.service # 停止服务 systemctl restart *.service # 重启服务 -systemctl reload *.service # 重新加载服务配置文件 -systemctl status *.service # 查询服务运行状态 +systemctl reload *.service # 重新加载服务配置文件 +systemctl status *.service # 查询服务运行状态 systemctl --failed # 显示启动失败的服务 ``` @@ -340,16 +350,12 @@ chmod +x /etc/rc.d/rc.local ```bash # 启动 /usr/local/nginx/sbin/nginx - # 重启 /usr/local/nginx/sbin/nginx -s reload - # 关闭进程 /usr/local/nginx/sbin/nginx -s stop - # 平滑关闭nginx /usr/local/nginx/sbin/nginx -s quit - # 查看nginx的安装状态, /usr/local/nginx/sbin/nginx -V ``` @@ -407,7 +413,7 @@ service iptables restart ``` -## nginx卸载 +## Nginx 卸载 如果通过yum安装,使用下面命令安装。 @@ -527,12 +533,14 @@ yum remove nginx 例如请求:`http://localhost:3000/test1/test2/test.php` +``` $host:localhost $server_port:3000 $request_uri:/test1/test2/test.php $document_uri:/test1/test2/test.php $document_root:/var/www/html $request_filename:/var/www/html/test1/test2/test.php +``` ### 符号参考 @@ -1083,7 +1091,7 @@ server { } ``` -### 跳转到带www的域上面 +### 跳转到带 www 的域上面 ```nginx server { @@ -1189,7 +1197,7 @@ location ^~/api/upload { } ``` -### ssl配置 +### SSL 配置 超文本传输安全协议(缩写:HTTPS,英语:Hypertext Transfer Protocol Secure)是超文本传输协议和SSL/TLS的组合,用以提供加密通讯及对网络服务器身份的鉴定。HTTPS连接经常被用于万维网上的交易支付和企业信息系统中敏感信息的传输。HTTPS不应与在RFC 2660中定义的安全超文本传输协议(S-HTTP)相混。HTTPS 目前已经是所有注重隐私和安全的网站的首选,随着技术的不断发展,HTTPS 网站已不再是大型网站的专利,所有普通的个人站长和博客均可以自己动手搭建一个安全的加密的网站。 @@ -1431,6 +1439,53 @@ if ($rule_1 = "21"){ } ``` +### cockpit + +https://github.com/cockpit-project/cockpit + +```nginx +server{ +    listen 80; +    server_name cockpit.xxxxxxx.com; +    return 301 https://$server_name$request_uri; +} + +server { +    listen 443 ssl; +    server_name cockpit.xxxxxxx.com; + +    #ssl on; +    ssl_certificate /etc/nginx/cert/cockpit.xxxxxxx.com.pem; +    ssl_certificate_key /etc/nginx/cert/cockpit.xxxxxxx.com.key; + +    location / { +        root /; +        index index.html; +        proxy_redirect off; +        proxy_pass http://websocket; +        proxy_http_version 1.1; +        proxy_set_header Upgrade $http_upgrade; +        proxy_set_header Connection "upgrade"; +        proxy_set_header Host $http_host; +    } +} +``` + +这时输入域名,能看到登录页面,但登录后,显示不出内容,页面全白。这里要对 `cockpit.conf` 进行设置修改。 + +```bash +sudo vim /etc/cockpit/cockpit.conf +``` + +参照如下配置修改,注意域名替换为 `your_domain_host`: + +```toml +[WebService] +Origins = https://cockpit.xxxxxxx.com https://127.0.0.1:9090 +ProtocolHeader = X-Forwarded-Proto +AllowUnencrypted = true +``` + ## 错误问题 ```bash @@ -1472,3 +1527,17 @@ server { - [Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA)](https://my.oschina.net/xshuai/blog/917097) - [Nginx 平滑升级](http://www.huxd.org/articles/2017/07/24/1500890692329.html) - [Nginx最新模块—ngx_http_mirror_module分析可以做版本发布前的预先验证,进行流量放大后的压测等等](https://mp.weixin.qq.com/s?__biz=MzIxNzg5ODE0OA==&mid=2247483708&idx=1&sn=90b0b1dccd9c337922a0588245277666&chksm=97f38cf7a08405e1928e0b46d923d630e529e7db8ac7ca2a91310a075986f8bcb2cee5b4953d#rd) + +## Contributors + +As always, thanks to our amazing contributors! + + + + + +Made with [action-contributors](https://github.com/jaywcjlove/github-action-contributors). + +## License + +Licensed under the MIT License. diff --git a/favicon.svg b/favicon.svg new file mode 100644 index 0000000..41e6312 --- /dev/null +++ b/favicon.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/idoc.yml b/idoc.yml new file mode 100644 index 0000000..2e1df53 --- /dev/null +++ b/idoc.yml @@ -0,0 +1,25 @@ +site: "Nginx 入门学习笔记" +logo: "./favicon.svg" +favicon: "./favicon.svg" + +homepage: https://wangchujiang.com/nginx-tutorial/ + +menus: + 首页: index.html + 捐赠: + url: https://wangchujiang.com/#/sponsor + target: __blank + 应用: + url: https://wangchujiang.com/#/app + target: __blank + +editButton: + label: 在 GitHub 上编辑此页面 + url: https://github.com/jaywcjlove/nginx-tutorial/tree/master/ +footer: | + App • + Projects • + Sponsor • + More Apps

+ Released under the MIT License. Copyright © 2024 Kenny Wong
+ Generated by idoc v{{idocVersion}} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..2c759d5 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json.schemastore.org/package.json", + "private": true, + "name": "nginx-tutorial", + "description": "Nginx 是一款面向性能设计的 HTTP 服务器,能反向代理 HTTP,HTTPS 和邮件相关(SMTP,POP3,IMAP)的协议链接。并且提供了负载均衡以及 HTTP 缓存。它的设计充分使用异步事件模型,削减上下文调度的开销,提高服务器并发能力。采用了模块化设计,提供了丰富模块的第三方模块。", + "homepage": "https://jaywcjlove.github.io/nginx-tutorial", + "version": "1.0.0", + "scripts": { + "start": "idoc --watch", + "build": "idoc" + }, + "repository": { + "type": "git", + "url": "https://github.com/jaywcjlove/nginx-tutorial" + }, + "keywords": [ + "nginx", + "tutorial", + "centos", + "Nginx 入门学习笔记" + ], + "dependencies": { + "idoc": "^1" + } +} \ No newline at end of file diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..5fe6b17 --- /dev/null +++ b/renovate.json @@ -0,0 +1,11 @@ +{ + "extends": [ + "config:base" + ], + "packageRules": [ + { + "matchPackagePatterns": ["*"], + "rangeStrategy": "replace" + } + ] +}