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 源

# 在 /etc/yum.repos.d 目录下创建 openresty.repo 文件
echo > openresty.repo # 在 openresty.repo 中添加内容如下 [openresty]
name=Official OpenResty Open Source Repository for CentOS
baseurl=https://openresty.org/package/centos/$releasever/$basearch
skip_if_unavailable=False
gpgcheck=
repo_gpgcheck=
gpgkey=https://openresty.org/package/pubkey.gpg
enabled=
enabled_metadata=

  2.2 清空 yum 缓存并重建缓存

# 切换到root账户下操作
su root
yum clean all
yum makecache

  2.3 通过 yum 进行安装

# 搜索 openresty 软件包
sudo yum cache search openresty # 安装 openresty
sudo yum install openresty

  2.4 确定安装的位置

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

  2.5 启动 OpenResty

# 查看进程是否启动
ps -Af | grep nginx # 启动进程
openresty # 查看进程是否启动
ps -Af | grep nginx

  


3. OpenResty 管理命令

  3.1 启动

# 切换到 root 账户
su root # 启动命令
openresty

  3.2 停止

# 停止命令
openresty -s stop

  3.3 重新加载配置文件

# 重新加载
openresty -s reload

  3.4 检查配置文件正确性

# 检查文件
openresty -t

  3.5 查看帮助

# 查看帮助
sudo openresty -h

4. 配置 CentOS 上 Nginx Web 服务器

  4.1 修改 nginx.conf 

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

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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"'; log_format main escape=json $msec#$time_local#$clientRealIp#$http_client_time#$status#$request_body;
#access_log logs/access.log main;
access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; map $http_x_forwarded_for $clientRealIp {
~^(?P<firstAddr>[-\.]+),?.*$ $firstAddr;
} server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
error_page = $;
lua_need_request_body on;
content_by_lua 'local s =ngx.var.request_body';
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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 ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 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;
# }
#} }

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

<!DOCTYPE html>
<html>
<head>
<title>.html</title>
</head>
<body>
s101
</body>
</html>

  4.3 验证

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

  4.4 关闭 crond 服务

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

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

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

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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"'; log_format main escape=json $remote_addr#$http_client_time#$time_local#$status#$request_body; #access_log logs/access.log main;
access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; #反向代理
upstream servers{
server s101: weight=;
server s102: weight=;
}
map $http_x_forwarded_for $clientRealIp {
~^(?P<firstAddr>[-\.]+),?.*$ $firstAddr;
} server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; underscores_in_headers on; location / {
#root html;
#index index.html index.htm;
error_page = $;
lua_need_request_body on;
content_by_lua 'local s = ngx.var.request_body';
proxy_pass http://servers;
proxy_set_header Host $host;
proxy_set_header remote_user_ip $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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 ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 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;
# }
#} }

6. 测试代码

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL; /**
* 入口点程序
*/
public class Main {
public static void main(String[] args) throws Exception {
String strURL = "http://localhost/1.html" ;
URL url = new URL(strURL) ;
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置请求方式
conn.setRequestMethod("POST");
//设置发送的内容类型
conn.setRequestProperty("Content-Type" , "application/json");
//允许输出到服务器
conn.setDoOutput(true);
OutputStream out = conn.getOutputStream() ; 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" + "}" ;
out.write(json.getBytes());
out.flush();
out.close();
int code = conn.getResponseCode() ;
if(code == 200){
System.out.println("发送ok!!");
}
}
}

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. php使用 utf8_encode 来将特殊字符转成 utf8

    如果在接受 $_POST 或 $_GET 时发生类似的错误报告:SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF6te ...

  2. 大数据之presto

    1.概述 Presto是一个分布式SQL查询引擎,用于查询分布在一个或多个不同数据源中的大数据集.presto可以通过使用分布式查询,可以快速高效的完成海量数据的查询.它是完全基于内存的,所以速度非常 ...

  3. vue-cli watch/timer

    watch 监听函数 data:{ letter:'' }, watch:{ letter(){ xxxxxx } }, timer data(){ return{ timer:null } }, h ...

  4. js实现响应式瀑布流

    导读:瀑布流,又称瀑布流式布局.是比较流行的一种网站页面布局,视觉表现为参差不齐的多栏布局,随着页面滚动条向下滚动,这种布局还会不断加载数据块并附加至当前尾部.最早采用此布局的网站是Pinterest ...

  5. Trace & Error log in file

    1. Log机制 做一些大型项目的时候,对代码的调试最有效的办法往往是最直接.最简单的log机制: 即对可以出设置打印店,对应打印信息进行调试(当然是有gdb也许你会觉得很高大上,但是实际项目中,gd ...

  6. Eclipse中Maven WEB工程tomcat调试

    最近没事了玩一下maven,使用maven管理工程中的依赖包非常的方便.建立maven web工程的时候开始不知道怎么用tomcat来调试,总是使用mave的tomcat插件发布了后来调试,觉得非常的 ...

  7. thinkphp 返回上一页的两种方式

    <div > <a class="details_back" href="{:U('Admin/SinglePageManagement/index') ...

  8. 【ZeroMQ】1、ZeroMQ(java)入门之Requerst/Response模式

    自己最开始是在cloud foundry中接触过消息服务器(nats),或者说是消息中间件,也算是初步知道了一个消息服务器对于分布式的网络系统的重要性,后来自己也曾想过在一些项目中使用它,尤其是在一些 ...

  9. Linux常用基本命令(cut)

    cut命令 作用:从文件的每一行剪切字节,字符或者字段,类似与编程语言中的字符串截取函数 格式:cut [option] [file] -b:仅显示行中指定直接范围的内容: -c:仅显示行中指定范围的 ...

  10. AOP 应用 性能

    AOP 我的感觉是做些日志什么的比较好,比如在每个controller的api前后搞一下,或者做些metric.今天在spring里用了下AOP并简单的测了一下性能. 使用 业务类 public cl ...