0. 说明


1. Windows 下安装

  下载软件包 openresty-1.13.6.1-win32.zip ,解压即可食用。

  【开启】

  直接运行 nginx.exe

  在 Windows 的命令窗口执行 netstat -ano 验证是否开启成功

  


2. Linux 下安装

  2.0 说明

  采用 yum 的方式将 OpenResty 安装在 CentOS 7 中

  2.1 添加 yum 源

  1. # 在 /etc/yum.repos.d 目录下创建 openresty.repo 文件
  2. echo > openresty.repo
  3.  
  4. # 在 openresty.repo 中添加内容如下
  5.  
  6. [openresty]
  7. name=Official OpenResty Open Source Repository for CentOS
  8. baseurl=https://openresty.org/package/centos/$releasever/$basearch
  9. skip_if_unavailable=False
  10. gpgcheck=
  11. repo_gpgcheck=
  12. gpgkey=https://openresty.org/package/pubkey.gpg
  13. enabled=
  14. enabled_metadata=

  2.2 清空 yum 缓存并重建缓存

  1. # 切换到root账户下操作
  2. su root
  3. yum clean all
  4. yum makecache

  2.3 通过 yum 进行安装

  1. # 搜索 openresty 软件包
  2. sudo yum cache search openresty
  3.  
  4. # 安装 openresty
  5. sudo yum install openresty

  2.4 确定安装的位置

  1. [centos@s101 /usr/local]$ which openresty
  2. /usr/bin/openresty

  2.5 启动 OpenResty

  1. # 查看进程是否启动
  2. ps -Af | grep nginx
  3.  
  4. # 启动进程
  5. openresty
  6.  
  7. # 查看进程是否启动
  8. ps -Af | grep nginx

  


3. OpenResty 管理命令

  3.1 启动

  1. # 切换到 root 账户
  2. su root
  3.  
  4. # 启动命令
  5. openresty

  3.2 停止

  1. # 停止命令
  2. openresty -s stop

  3.3 重新加载配置文件

  1. # 重新加载
  2. openresty -s reload

  3.4 检查配置文件正确性

  1. # 检查文件
  2. openresty -t

  3.5 查看帮助

  1. # 查看帮助
  2. sudo openresty -h

4. 配置 CentOS 上 Nginx Web 服务器

  4.1 修改 nginx.conf 

  在 /usr/local/openresty/nginx/conf 目录下修改 nginx.conf

  1. #user nobody;
  2. worker_processes ;
  3.  
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9.  
  10. events {
  11. worker_connections ;
  12. }
  13.  
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17.  
  18. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. # '$status $body_bytes_sent "$http_referer" '
  20. # '"$http_user_agent" "$http_x_forwarded_for"';
  21.  
  22. log_format main escape=json $msec#$time_local#$clientRealIp#$http_client_time#$status#$request_body;
  23. #access_log logs/access.log main;
  24. access_log logs/access.log main;
  25.  
  26. sendfile on;
  27. #tcp_nopush on;
  28.  
  29. #keepalive_timeout ;
  30. keepalive_timeout ;
  31.  
  32. #gzip on;
  33.  
  34. map $http_x_forwarded_for $clientRealIp {
  35. ~^(?P<firstAddr>[-\.]+),?.*$ $firstAddr;
  36. }
  37.  
  38. server {
  39. listen ;
  40. server_name localhost;
  41.  
  42. #charset koi8-r;
  43.  
  44. #access_log logs/host.access.log main;
  45.  
  46. location / {
  47. root html;
  48. index index.html index.htm;
  49. error_page = $;
  50. lua_need_request_body on;
  51. content_by_lua 'local s =ngx.var.request_body';
  52. }
  53.  
  54. #error_page /.html;
  55.  
  56. # redirect server error pages to the static page /50x.html
  57. #
  58. error_page /50x.html;
  59. location = /50x.html {
  60. root html;
  61. }
  62.  
  63. # proxy the PHP scripts to Apache listening on 127.0.0.1:
  64. #
  65. #location ~ \.php$ {
  66. # proxy_pass http://127.0.0.1;
  67. #}
  68.  
  69. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
  70. #
  71. #location ~ \.php$ {
  72. # root html;
  73. # fastcgi_pass 127.0.0.1:;
  74. # fastcgi_index index.php;
  75. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  76. # include fastcgi_params;
  77. #}
  78.  
  79. # deny access to .htaccess files, if Apache's document root
  80. # concurs with nginx's one
  81. #
  82. #location ~ /\.ht {
  83. # deny all;
  84. #}
  85. }
  86.  
  87. # another virtual host using mix of IP-, name-, and port-based configuration
  88. #
  89. #server {
  90. # listen ;
  91. # listen somename:;
  92. # server_name somename alias another.alias;
  93.  
  94. # location / {
  95. # root html;
  96. # index index.html index.htm;
  97. # }
  98. #}
  99.  
  100. # HTTPS server
  101. #
  102. #server {
  103. # listen ssl;
  104. # server_name localhost;
  105.  
  106. # ssl_certificate cert.pem;
  107. # ssl_certificate_key cert.key;
  108.  
  109. # ssl_session_cache shared:SSL:1m;
  110. # ssl_session_timeout 5m;
  111.  
  112. # ssl_ciphers HIGH:!aNULL:!MD5;
  113. # ssl_prefer_server_ciphers on;
  114.  
  115. # location / {
  116. # root html;
  117. # index index.html index.htm;
  118. # }
  119. #}
  120.  
  121. }

   4.2 在 /usr/local/openresty/nginx/html 下新建 1.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>.html</title>
  5. </head>
  6. <body>
  7. s101
  8. </body>
  9. </html>

  4.3 验证

  1. # 在关闭防火墙的情况下在浏览器中输入以下
  2. http://s101/1.html

  4.4 关闭 crond 服务

  1. [root@s101 /usr/local/openresty/nginx/html]# service crond stop
  2. Redirecting to /bin/systemctl stop crond.service

5. Windows下配置反向代理服务器

  修改配置文件 openresty-1.13.6.2-win64\conf\nginx.conf

  1. #user nobody;
  2. worker_processes ;
  3.  
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9.  
  10. events {
  11. worker_connections ;
  12. }
  13.  
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17.  
  18. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. # '$status $body_bytes_sent "$http_referer" '
  20. # '"$http_user_agent" "$http_x_forwarded_for"';
  21.  
  22. log_format main escape=json $remote_addr#$http_client_time#$time_local#$status#$request_body;
  23.  
  24. #access_log logs/access.log main;
  25. access_log logs/access.log main;
  26.  
  27. sendfile on;
  28. #tcp_nopush on;
  29.  
  30. #keepalive_timeout ;
  31. keepalive_timeout ;
  32.  
  33. #gzip on;
  34.  
  35. #反向代理
  36. upstream servers{
  37. server s101: weight=;
  38. server s102: weight=;
  39. }
  40. map $http_x_forwarded_for $clientRealIp {
  41. ~^(?P<firstAddr>[-\.]+),?.*$ $firstAddr;
  42. }
  43.  
  44. server {
  45. listen ;
  46. server_name localhost;
  47.  
  48. #charset koi8-r;
  49.  
  50. #access_log logs/host.access.log main;
  51.  
  52. underscores_in_headers on;
  53.  
  54. location / {
  55. #root html;
  56. #index index.html index.htm;
  57. error_page = $;
  58. lua_need_request_body on;
  59. content_by_lua 'local s = ngx.var.request_body';
  60. proxy_pass http://servers;
  61. proxy_set_header Host $host;
  62. proxy_set_header remote_user_ip $remote_addr;
  63. proxy_set_header X-Forwarded-For
  64. $proxy_add_x_forwarded_for;
  65. }
  66.  
  67. #error_page /.html;
  68.  
  69. # redirect server error pages to the static page /50x.html
  70. #
  71. error_page /50x.html;
  72. location = /50x.html {
  73. root html;
  74. }
  75.  
  76. # proxy the PHP scripts to Apache listening on 127.0.0.1:
  77. #
  78. #location ~ \.php$ {
  79. # proxy_pass http://127.0.0.1;
  80. #}
  81.  
  82. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
  83. #
  84. #location ~ \.php$ {
  85. # root html;
  86. # fastcgi_pass 127.0.0.1:;
  87. # fastcgi_index index.php;
  88. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  89. # include fastcgi_params;
  90. #}
  91.  
  92. # deny access to .htaccess files, if Apache's document root
  93. # concurs with nginx's one
  94. #
  95. #location ~ /\.ht {
  96. # deny all;
  97. #}
  98. }
  99.  
  100. # another virtual host using mix of IP-, name-, and port-based configuration
  101. #
  102. #server {
  103. # listen ;
  104. # listen somename:;
  105. # server_name somename alias another.alias;
  106.  
  107. # location / {
  108. # root html;
  109. # index index.html index.htm;
  110. # }
  111. #}
  112.  
  113. # HTTPS server
  114. #
  115. #server {
  116. # listen ssl;
  117. # server_name localhost;
  118.  
  119. # ssl_certificate cert.pem;
  120. # ssl_certificate_key cert.key;
  121.  
  122. # ssl_session_cache shared:SSL:1m;
  123. # ssl_session_timeout 5m;
  124.  
  125. # ssl_ciphers HIGH:!aNULL:!MD5;
  126. # ssl_prefer_server_ciphers on;
  127.  
  128. # location / {
  129. # root html;
  130. # index index.html index.htm;
  131. # }
  132. #}
  133.  
  134. }

6. 测试代码

  1. import java.io.OutputStream;
  2. import java.net.HttpURLConnection;
  3. import java.net.URL;
  4.  
  5. /**
  6. * 入口点程序
  7. */
  8. public class Main {
  9. public static void main(String[] args) throws Exception {
  10. String strURL = "http://localhost/1.html" ;
  11. URL url = new URL(strURL) ;
  12. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  13. //设置请求方式
  14. conn.setRequestMethod("POST");
  15. //设置发送的内容类型
  16. conn.setRequestProperty("Content-Type" , "application/json");
  17. //允许输出到服务器
  18. conn.setDoOutput(true);
  19. OutputStream out = conn.getOutputStream() ;
  20.  
  21. String json = "{\n" + " \"appChannel\": \"anroid bus\",\n" + " \"appId\": \"sohuvideo\",\n" + " \"appPlatform\": \"ios\",\n" + " \"appVersion\": \"1.1.0\",\n" + " \"deviceStyle\": \"oppo 1\",\n" + " \"errorLogs\": [\n" + " {\n" + " \"appChannel\": \"umeng\",\n" + " \"appId\": \"gaodemap\",\n" + " \"appPlatform\": \"blackberry\",\n" + " \"appVersion\": \"1.1.0\",\n" + " \"deviceStyle\": \"vivo 3\",\n" + " \"errorBrief\": \"at cn.lift.dfdf.web.AbstractBaseController.validInbound(AbstractBaseController.java:72)\",\n" + " \"errorDetail\": \"at cn.lift.dfdfdf.control.CommandUtil.getInfo(CommandUtil.java:67) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606)\",\n" + " \"osType\": \"android 4.0\",\n" + " \"tenantId\": \"tnt023\"\n" + " }\n" + " ],\n" + " \"eventLogs\": [\n" + " {\n" + " \"appChannel\": \"anroid bus\",\n" + " \"appId\": \"tianya\",\n" + " \"appPlatform\": \"android\",\n" + " \"appVersion\": \"2.0.0\",\n" + " \"deviceStyle\": \"红米\",\n" + " \"eventId\": \"popmenu\",\n" + " \"osType\": \"ios11\",\n" + " \"tenantId\": \"tnt009\"\n" + " },\n" + " {\n" + " \"appChannel\": \"appstore\",\n" + " \"appId\": \"gaodemap\",\n" + " \"appPlatform\": \"android\",\n" + " \"appVersion\": \"1.1.0\",\n" + " \"deviceStyle\": \"iphone 7 plus\",\n" + " \"eventId\": \"popmenu\",\n" + " \"osType\": \"android 4.0\",\n" + " \"tenantId\": \"tnt009\"\n" + " },\n" + " {\n" + " \"appChannel\": \"appstore\",\n" + " \"appId\": \"faobengplay\",\n" + " \"appPlatform\": \"blackberry\",\n" + " \"appVersion\": \"1.0.0\",\n" + " \"deviceStyle\": \"vivo 3\",\n" + " \"eventId\": \"autoImport\",\n" + " \"osType\": \"ios11\",\n" + " \"tenantId\": \"tnt009\"\n" + " },\n" + " {\n" + " \"appChannel\": \"anroid bus\",\n" + " \"appId\": \"tianya\",\n" + " \"appPlatform\": \"blackberry\",\n" + " \"appVersion\": \"1.1.0\",\n" + " \"deviceStyle\": \"iphone 7 plus\",\n" + " \"eventId\": \"popmenu\",\n" + " \"osType\": \"mi 5.5\",\n" + " \"tenantId\": \"tnt009\"\n" + " },\n" + " {\n" + " \"appChannel\": \"anroid bus\",\n" + " \"appId\": \"tianya\",\n" + " \"appPlatform\": \"android\",\n" + " \"appVersion\": \"1.2.0\",\n" + " \"deviceStyle\": \"iphone 7\",\n" + " \"eventId\": \"bookstore\",\n" + " \"osType\": \"ios11\",\n" + " \"tenantId\": \"tnt501\"\n" + " }\n" + " ],\n" + " \"osType\": \"ios11\",\n" + " \"pageLogs\": [\n" + " null,\n" + " null,\n" + " null,\n" + " null,\n" + " null\n" + " ],\n" + " \"startupLogs\": [\n" + " {\n" + " \"appChannel\": \"anroid bus\",\n" + " \"appId\": \"faobengplay\",\n" + " \"appPlatform\": \"ios\",\n" + " \"appVersion\": \"1.2.0\",\n" + " \"brand\": \"魅族\",\n" + " \"carrier\": \"中国铁通\",\n" + " \"country\": \"america\",\n" + " \"deviceStyle\": \"vivo 3\",\n" + " \"network\": \"wifi\",\n" + " \"osType\": \"android 4.0\",\n" + " \"province\": \"guangdong\",\n" + " \"screenSize\": \"480 * 320\",\n" + " \"tenantId\": \"tnt501\"\n" + " },\n" + " {\n" + " \"appChannel\": \"appstore\",\n" + " \"appId\": \"sohuvideo\",\n" + " \"appPlatform\": \"blackberry\",\n" + " \"appVersion\": \"2.0.0\",\n" + " \"brand\": \"Apple\",\n" + " \"carrier\": \"中国铁通\",\n" + " \"country\": \"china\",\n" + " \"deviceStyle\": \"iphone 7\",\n" + " \"network\": \"3g\",\n" + " \"osType\": \"ios11\",\n" + " \"province\": \"guangxi\",\n" + " \"screenSize\": \"1136 * 640\",\n" + " \"tenantId\": \"tnt501\"\n" + " }\n" + " ],\n" + " \"tenantId\": \"tnt009\",\n" + " \"usageLogs\": [\n" + " {\n" + " \"appChannel\": \"umeng\",\n" + " \"appId\": \"gaodemap\",\n" + " \"appPlatform\": \"winphone\",\n" + " \"appVersion\": \"1.1.0\",\n" + " \"deviceStyle\": \"iphone 7\",\n" + " \"osType\": \"ios11\",\n" + " \"tenantId\": \"tnt009\"\n" + " },\n" + " {\n" + " \"appChannel\": \"anroid bus\",\n" + " \"appId\": \"tianya\",\n" + " \"appPlatform\": \"android\",\n" + " \"appVersion\": \"1.2.0\",\n" + " \"deviceStyle\": \"iphone 6\",\n" + " \"osType\": \"android 4.0\",\n" + " \"tenantId\": \"tnt501\"\n" + " },\n" + " {\n" + " \"appChannel\": \"umeng\",\n" + " \"appId\": \"tianya\",\n" + " \"appPlatform\": \"winphone\",\n" + " \"appVersion\": \"1.0.0\",\n" + " \"deviceStyle\": \"vivo 3\",\n" + " \"osType\": \"mi 5.5\",\n" + " \"tenantId\": \"tnt023\"\n" + " },\n" + " {\n" + " \"appChannel\": \"umeng\",\n" + " \"appId\": \"sohuvideo\",\n" + " \"appPlatform\": \"android\",\n" + " \"appVersion\": \"1.0.0\",\n" + " \"deviceStyle\": \"iphone 6 plus\",\n" + " \"osType\": \"mi 5.5\",\n" + " \"tenantId\": \"tnt023\"\n" + " }\n" + " ]\n" + "}" ;
  22. out.write(json.getBytes());
  23. out.flush();
  24. out.close();
  25. int code = conn.getResponseCode() ;
  26. if(code == 200){
  27. System.out.println("发送ok!!");
  28. }
  29. }
  30. }

OpenResty 安装配置的更多相关文章

  1. openresty安装配置 Ubuntu下

    1.进入openresty-1.11.2.4的压缩包木木,我这里是在“/usr/local/”下: 2.进入后执行[tar -xzvf openresty-1.11.2.4.tar.gz]进行解压 3 ...

  2. openresty安装配置

    在centos7上操作的. 上周搞了两天的Nginx的location rewrite,突然,对Nginx有了更好的理解. 所以持续一下. yum install readline-devel pcr ...

  3. Openresty安装及使用配置(OPENRESTY+NGINX)

    Openresty 简介 Openresty是一个基于NGINX和Lua的高性能Web平台,内部有大量的Lua库和第三方模块,能够很方便的搭建处理高并发,扩展性高的Web平台和动态网关,充分利用 Ng ...

  4. Openresty 安装教程

    Openresty的简单安装方法,如需高级编译安装,请参照安装选项 1.安装配置好Yum源,不赘述此步骤 2.安装必要组件 yum install pcre-devel openssl-devel g ...

  5. zabbix安装配置

    实验环境 主机名 操作系统版本 IP地址 安装软件 console CentOS 7.0 114.55.29.246 Httpd.Nginx.MySQL.Zabbix log1 CentOS 7.0 ...

  6. Disconf 分布式配置管理平台(安装配置)

    Disconf 分布式配置管理平台(安装配置) 依赖环境 Nginx:处理静态资源请求.动态请求转发到Tomcat Tomcat:处理Nginx的请求 Redis:用户session管理 MySQL: ...

  7. openresty安装文档

    一.OpenResty简介    OpenResty是一个基于 Nginx与 Lua的高性能 Web平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并 ...

  8. openresty安装笔记

    目录 安装步骤: openresty安装在ubuntu下的安装 参考 安装OpenResty(Nginx+Lua)开发环境 安装步骤: # 创建目录/usr/servers,以后我们把所有软件安装在此 ...

  9. Hive安装配置指北(含Hive Metastore详解)

    个人主页: http://www.linbingdong.com 本文介绍Hive安装配置的整个过程,包括MySQL.Hive及Metastore的安装配置,并分析了Metastore三种配置方式的区 ...

随机推荐

  1. postgresql 清空数据表数据

    在 mysql中,只需要执行: TRUNCATE table_name; 即可,数据会情况,而且自增id也会变回0: 但在 postgresql 则稍有不同,因为 postgresql 的自增id是通 ...

  2. JavaScript 视频教程 收藏

    001 JavaScript第1章 JavaScript概述 https://www.365yg.com/group/6410923214495940866/ 001 JavaScript第1章 Ja ...

  3. *2 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '[' in /application/nginx-1.6.3/html/zabbix/index.php on line 32" while reading response header from upstream, clien

    今天呢想学习一下zabbix监控一下我的服务情况,然后就开始安装我的zabbix服务,首先LNMP环境准备好了,Nginx版本为1.6.3,php版本为5.3.27,MySQL版本为二进制包安装的5. ...

  4. 我的MQ笔记

    1.安装IBM MQ 1.1.安装先决条件: (1)WebSphere  Eclipse  Platform  V3.01 (2)为Windows域用户配置WebSphere MQ用户 1.2.安装程 ...

  5. C# int? 关键字

    1.int?  关键字说明 (1).int? 表示一个int类型,且该int类型可空,如果不加?的话,那么int类型的默认值为0,不能赋null值,代码如下: int aa = null; (2).当 ...

  6. 5.C#知识点:ref和Out关键字浅谈

    首先我们要知道ref和out在C#里面是什么? 答:它们俩是C#里面的关键字. 他们俩是干啥的呢? 答:他们俩是方法参数的修饰符号,一但使用,方法定义和方法都用都要使用这个关键字,这一点是死规定. 好 ...

  7. Java服务CPU飙到99%问题排查

    最近生产环境中出现了一起CPU突然飙升的事件,下面介绍一下 CPU飙升问题排查的过程和解决方法. 该方案参考自:https://www.jianshu.com/p/e96c74133be6,感谢路遥N ...

  8. MyBatis开发Dao层的两种方式(原始Dao层开发)

    本文将介绍使用框架mybatis开发原始Dao层来对一个对数据库进行增删改查的案例. Mapper动态代理开发Dao层请阅读我的下一篇博客:MyBatis开发Dao层的两种方式(Mapper动态代理方 ...

  9. 【JavaFx教程】第一部分:Scene Builder

    第一部分的主题 开始了解 JavaFX . 创建并运行一个 JavaFX 项目. 使用 Scene Builder 来设计用户界面. 使用 模型 - 视图 - 控制器(MVC)模式 构造基础的应用. ...

  10. Java-函数式编程(二)Lambda表达式

    本文首发:Java-函数式编程(二)Lambda表达式 “Lambda 表达式”(lambda expression)是一个匿名函数,Lambda表达式基于数学中的λ演算得名,直接对应于其中的lamb ...