Nginx 常用配置清单

沙海 2021年4月23日01:37:28Java评论31字数 2122阅读7分4秒阅读模式
摘要

Nginx 常用配置清单 vishnu InfoQ

Nginx 常用配置清单

vishnu InfoQ 文章源自JAVA秀-https://www.javaxiu.com/19737.html

Nginx 常用配置清单文章源自JAVA秀-https://www.javaxiu.com/19737.html

作者 | vishnu chilamakuru文章源自JAVA秀-https://www.javaxiu.com/19737.html

文章源自JAVA秀-https://www.javaxiu.com/19737.html

Nginx 是一个高性能的 HTTP 和反向代理 web 服务器,同时也提供了 IMAP/POP3/SMTP 服务,其因丰富的功能集、稳定性、示例配置文件和低系统资源的消耗受到了开发者的欢迎。本文,我们总结了一些常用的 Nginx 配置代码,希望对大家有所帮助。文章源自JAVA秀-https://www.javaxiu.com/19737.html

 侦听端口文章源自JAVA秀-https://www.javaxiu.com/19737.html

    server {# Standard HTTP Protocollisten80;# Standard HTTPS Protocollisten443 ssl;# For http2listen443 ssl http2;# Listen on 80 using IPv6listen [::]:80;# Listen only on using IPv6listen [::]:80 ipv6only=on;}
    文章源自JAVA秀-https://www.javaxiu.com/19737.html

     访问日志文章源自JAVA秀-https://www.javaxiu.com/19737.html

      server {# Relative or full path to log fileaccess_log /path/to/file.log;# Turn 'on' or 'off'access_logon;}
      文章源自JAVA秀-https://www.javaxiu.com/19737.html

       域名文章源自JAVA秀-https://www.javaxiu.com/19737.html

        server {# Listen to yourdomain.comserver_name yourdomain.com;# Listen to multiple domainsserver_name yourdomain.com www.yourdomain.com;# Listen to all domainsserver_name*.yourdomain.com;# Listen to all top-level domainsserver_nameyourdomain.*;# Listen to unspecified Hostnames (Listens to IP address itself)server_name"";}
        文章源自JAVA秀-https://www.javaxiu.com/19737.html

         静态资产文章源自JAVA秀-https://www.javaxiu.com/19737.html

          server {listen80;server_name yourdomain.com;location / {root /path/to/website; } }
          文章源自JAVA秀-https://www.javaxiu.com/19737.html

           重定向文章源自JAVA秀-https://www.javaxiu.com/19737.html

            server {listen80;server_name www.yourdomain.com;return301 http://yourdomain.com$request_uri;}server {listen80;server_name www.yourdomain.com;location /redirect-url {return301 http://otherdomain.com; }}
            文章源自JAVA秀-https://www.javaxiu.com/19737.html

             反向代理文章源自JAVA秀-https://www.javaxiu.com/19737.html

              server {listen80;server_name yourdomain.com;location / {proxy_pass http://0.0.0.0:3000;# where 0.0.0.0:3000 is your application server (Ex: node.js) bound on 0.0.0.0 listening on port 3000 }}
              文章源自JAVA秀-https://www.javaxiu.com/19737.html

               负载均衡文章源自JAVA秀-https://www.javaxiu.com/19737.html

                upstream node_js {server0.0.0.0:3000;server0.0.0.0:4000;server123.131.121.122;}server {listen80;server_name yourdomain.com;location / {proxy_pass http://node_js; }}
                文章源自JAVA秀-https://www.javaxiu.com/19737.html

                 SSL 协议文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  server {listen443 ssl;server_name yourdomain.com;sslon;ssl_certificate /path/to/cert.pem;ssl_certificate_key /path/to/privatekey.pem;ssl_staplingon;ssl_stapling_verifyon;ssl_trusted_certificate /path/to/fullchain.pem;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_session_timeout1h;ssl_session_cache shared:SSL:50m;add_header Strict-Transport-Security max-age=15768000;}# Permanent Redirect for HTTP to HTTPSserver {listen80;server_name yourdomain.com;return301 https://$host$request_uri;}
                  文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  原文链接:文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  https://vishnu.hashnode.dev/nginx-cheatsheet?guid=none&deviceId=ca2b0a4c-a1fb-43bc-ab8c-1eaafe592469文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  今日好文推荐文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  故意向Linux内核提交漏洞被全线拉黑?华人教授行为引众怒文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  3年迭代一次技术栈:我们程序员,为啥跑不赢行业?文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  独家:“论文致谢刷屏”博士演讲干货文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  每周精要上线移动端,立刻订阅,你将获得文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  InfoQ 用户每周必看的精华内容集合:文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  资深技术编辑撰写或编译的全球 IT 要闻文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  一线技术专家撰写的实操技术案例文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  InfoQ 出品的课程技术活动报名通道;文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  “码”上关注,订阅每周新鲜资讯文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  Nginx 常用配置清单文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  点个在看少个 bug?文章源自JAVA秀-https://www.javaxiu.com/19737.html

                  继续阅读
                  速蛙云 - 极致体验,强烈推荐!!!购买套餐就免费送各大视频网站会员!快速稳定、独家福利社、流媒体稳定解锁!速度快,全球上网、视频、游戏加速、独立IP均支持!基础套餐性价比很高!这里不多说,我一直正在使用,推荐购买:https://www.javaxiu.com/59919.html
                  weinxin
                  资源分享QQ群
                  本站是JAVA秀团队的技术分享社区, 会经常分享资源和教程; 分享的时代, 请别再沉默!
                  沙海
                  • 版权声明:本站是JAVA秀团队的技术分享社区,我们会经常分享资源和教程。
                  • 转载请注明:Nginx 常用配置清单 - JAVA秀 ☜(ˆ▽ˆ)
                  匿名

                  发表评论

                  匿名网友 填写信息

                  :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

                  确定