下載軟件包 openresty-1.13.6.1-win32.zip ,解壓便可食用。php
【開啓】html
直接運行 nginx.exejava
在 Windows 的命令窗口執行 netstat -ano 驗證是否開啓成功android
採用 yum 的方式將 OpenResty 安裝在 CentOS 7 中ios
# 在 /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=1 repo_gpgcheck=1 gpgkey=https://openresty.org/package/pubkey.gpg enabled=1 enabled_metadata=1
# 切換到root帳戶下操做 su root yum clean all yum makecache
# 搜索 openresty 軟件包
sudo yum cache search openresty
# 安裝 openresty
sudo yum install openresty
[centos@s101 /usr/local]$ which openresty
/usr/bin/openresty
# 查看進程是否啓動 ps -Af | grep nginx # 啓動進程 openresty # 查看進程是否啓動 ps -Af | grep nginx
# 切換到 root 帳戶
su root
# 啓動命令
openresty
# 中止命令
openresty -s stop
# 從新加載
openresty -s reload
# 檢查文件
openresty -t
# 查看幫助
sudo openresty -h
在 /usr/local/openresty/nginx/conf 目錄下修改 nginx.confnginx
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } 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 0; keepalive_timeout 65; #gzip on; map $http_x_forwarded_for $clientRealIp { ~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; error_page 405 =200 $1; lua_need_request_body on; content_by_lua 'local s =ngx.var.request_body'; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # 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 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 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; # } #} }
<!DOCTYPE html> <html> <head> <title>1.html</title> </head> <body> s101 </body> </html>
# 在關閉防火牆的狀況下在瀏覽器中輸入如下 http://s101/1.html
[root@s101 /usr/local/openresty/nginx/html]# service crond stop
Redirecting to /bin/systemctl stop crond.service
修改配置文件 openresty-1.13.6.2-win64\conf\nginx.confweb
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } 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 0; keepalive_timeout 65; #gzip on; #反向代理 upstream servers{ server s101:80 weight=1; server s102:80 weight=1; } map $http_x_forwarded_for $clientRealIp { ~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr; } server { listen 80; 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 405 =200 $1; 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 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # 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 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 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; # } #} }
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!!"); } } }