Comments (9)
It maybe is caused by lack of file access permission which let jvm can not access needed jar files and can not start.
Please check the user configuration in nginx.conf and make sure the user can access all jars in the classpath.
By default user nobody
is used to start nginx worker process viz. jvm process when we use root to run nginx master.
BTW to get more detail debug info we can enable nginx debug log and check the error.log.
## By default user `nobody` is used to start nginx worker process viz. jvm process when we use root to run nginx master.
user myUserToStartJvm;
error_log logs/error.log debug;
http {
.....
}
from nginx-clojure.
nginx-clojure-embed is recommended if you want to debug/test nginx-clojure handlers . You can debug/test your handlers just like general java program in your favorite IDE without need of remote debug.
e.g.
<dependency>
<groupId>nginx-clojure</groupId>
<artifactId>nginx-clojure-embed</artifactId>
<version>0.6.0</version>
</dependency>
//Start it with with a nginx.conf file
NginxEmbedServer.getServer().start("/my-dir/nginx.conf");
//Stop the server
NginxEmbedServer.getServer().stop();
from nginx-clojure.
Thanks for the good answer for my lack of knowledge. As you said, I ran it in the editor using nginx-clojure-embed. It seems to be working correctly to me.
package org.example;
import nginx.clojure.embed.NginxEmbedServer;
public class Main {
public static void main(String[] args) {
NginxEmbedServer.getServer().start("/Users/choijinsu/Downloads/nginx-clojure-0.6.0/conf/nginx.conf");
//Stop the server
NginxEmbedServer.getServer().stop();
}
}
2023-05-18 03:02:18[info][62870][main][nginx-clojure embed] starting......
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /Users/choijinsu/Downloads/nginx-clojure-0.6.0/conf/nginx.conf:1
2023-05-18 03:02:18[info][62870][main][nginx-clojure embed] finish configuration check
2023-05-18 03:02:19[info][62870][main][nginx-clojure embed] server started!
2023-05-18 03:02:19[info][62870][main][nginx-clojure embed] server stopping.....
2023-05-18 03:02:19[info][62870][main][nginx-clojure embed] server stopped
But If I run sudo ./nginx
afterwards, the same problem occurs.
Here is error.log
and nginx.conf
user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log debug;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
jvm_classpath_check off;
sendfile on;
keepalive_timeout 65;
#gzip on;
jvm_path "/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home";
#jvm_classpath "libs/*:jars/*";
jvm_classpath "/Users/choijinsu/Downloads/nginx-clojure-0.6.0/jars/mavenTest-1.0-SNAPSHOT.jar";
jvm_options "-Xms1024m";
jvm_options "-Xmx1024m";
jvm_options "--illegal-access=deny";
jvm_options "--add-opens=java.base/java.lang=ALL-UNNAMED";
jvm_options "--add-opens=java.base/sun.nio.cs=ALL-UNNAMED";
#jvm_workers 8;
server {
listen 80;
server_name localhost;
location / {
proxy_pass https://www.google.com;
}
location /search {
proxy_pass https://www.google.com/search;
body_filter_type "java";
body_filter_name "org.example.replacer.GoogleLogoReplacer";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
2023/05/18 03:02:56 [debug] 63449#0: bind() 0.0.0.0:80 #8
2023/05/18 03:02:56 [notice] 63449#0: using the "kqueue" event method
2023/05/18 03:02:56 [debug] 63449#0: counter: 0000000101EE8080, 1
2023/05/18 03:02:56 [notice] 63449#0: nginx-clojure/0.6.0
2023/05/18 03:02:56 [debug] 63449#0: in master, ngx_last_process:0, s:0
2023/05/18 03:02:56 [notice] 63449#0: nginx/1.23.3
2023/05/18 03:02:56 [notice] 63449#0: built by clang 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
2023/05/18 03:02:56 [notice] 63449#0: OS: Darwin 22.4.0
2023/05/18 03:02:56 [notice] 63449#0: hw.ncpu: 16
2023/05/18 03:02:56 [notice] 63449#0: net.inet.tcp.sendspace: 131072
2023/05/18 03:02:56 [notice] 63449#0: kern.ipc.somaxconn: 128
2023/05/18 03:02:56 [notice] 63449#0: getrlimit(RLIMIT_NOFILE): 1024:9223372036854775807
2023/05/18 03:02:56 [debug] 63450#0: write: 5, 00007FF7BE4B4760, 6, 0
2023/05/18 03:02:56 [debug] 63450#0: setproctitle: "nginx: master process ./nginx"
2023/05/18 03:02:56 [notice] 63450#0: start worker processes
2023/05/18 03:02:56 [debug] 63450#0: channel 3:5
2023/05/18 03:02:56 [notice] 63450#0: start worker process 63451
2023/05/18 03:02:56 [debug] 63450#0: sigsuspend
2023/05/18 03:02:56 [debug] 63451#0: add cleanup: 00007FB94980FF10
2023/05/18 03:02:56 [debug] 63451#0: malloc: 00007FB948B040C0:8
2023/05/18 03:02:56 [debug] 63451#0: malloc: 00007FB949814200:16384
2023/05/18 03:02:56 [debug] 63451#0: malloc: 00007FB949818200:16384
2023/05/18 03:02:56 [debug] 63451#0: malloc: 00007FB948817000:237568
2023/05/18 03:02:56 [debug] 63451#0: malloc: 00007FB948851000:106496
2023/05/18 03:02:56 [debug] 63451#0: malloc: 00007FB94886B000:106496
2023/05/18 03:02:56 [debug] 63451#0: kevent set event: 8: ft:-1 fl:0005
2023/05/18 03:02:56 [debug] 63451#0: setproctitle: "nginx: worker process"
2023/05/18 03:02:56 [debug] 63451#0: posix_memalign: 00007FB948800000:40960 @16
2023/05/18 03:02:56 [error] 63451#0: can not initialize jvm for load dynamic lib, maybe wrong jvm_path!
2023/05/18 03:02:56 [error] 63451#0: can not initialize jvm for load dynamic lib, maybe wrong jvm_path!
2023/05/18 03:02:56 [debug] 63451#0: free: 00007FB948800000, unused: 40583
2023/05/18 03:02:56 [error] 63451#0: jvm start times 1
2023/05/18 03:02:56 [error] 63451#0: jvm start times 1
2023/05/18 03:02:56 [notice] 63450#0: signal 20 (SIGCHLD) received from 63451
2023/05/18 03:02:56 [notice] 63450#0: worker process 63451 exited with code 2
2023/05/18 03:02:56 [alert] 63450#0: worker process 63451 exited with fatal code 2 and cannot be respawned
2023/05/18 03:02:56 [alert] 63450#0: worker process 63451 exited with fatal code 2 and cannot be respawned
2023/05/18 03:02:56 [debug] 63450#0: shmtx forced unlock
2023/05/18 03:02:56 [debug] 63450#0: wake up, sigio 0
2023/05/18 03:02:56 [debug] 63450#0: reap children
2023/05/18 03:02:56 [debug] 63450#0: child: 0 63451 e:0 t:1 d:0 r:0 j:0
2023/05/18 03:02:56 [debug] 63450#0: sigsuspend
2023/05/18 03:02:56 [notice] 63450#0: signal 23 (SIGIO) received
2023/05/18 03:02:56 [debug] 63450#0: wake up, sigio 0
from nginx-clojure.
It seams that jvm path is wrong. It should be auto
or the jvm dynamic library path.
Here's an example
###define jvm path, auto for auto-detect jvm path or a real path
###for win32, jvm_path maybe is "C:/Program Files/Java/jdk1.7.0_25/jre/bin/server/jvm.dll";
###for macosx, jvm_path maybe is "/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre/lib/server/libjvm.dylib";
##for ubuntu, jvm_path maybe is "/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server/libjvm.so";
###for centos, jvm_path maybe is "/usr/java/jdk1.6.0_45/jre/lib/amd64/server/libjvm.so";
###for centos 32bit, jvm_path maybe is "/usr/java/jdk1.7.0_51/jre/lib/i386/server/libjvm.so";
jvm_path auto;
from nginx-clojure.
thank you for the reply. The server is now running and i can enter localhost. But when I do the search, it throws BufferOverflowException. This is jvm_options "-Xmx1024m"; Is it caused by exceeding Increasing this value does not solve it.
@Override
protected Object[] doFilter(Map<String, Object> request, String body, boolean isResponse) throws IOException {
Document doc = Jsoup.parse(body);
Element logo = doc.select("img.jfN4p").first();
if (logo != null) {
logo.attr("src", "http://via.placeholder.com/400");
}
return new Object[] {200, new ArrayMap<>(new Object[]{"Content-Type", "text/html"}), doc.toString()};
}
2023-05-18 15:32:25[info][99238][main][nginx-clojure embed] starting......
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /Users/choijinsu/Downloads/nginx-clojure-0.6.0/conf/nginx.conf:1
2023-05-18 15:32:25[info][99238][main][nginx-clojure embed] finish configuration check
2023-05-18 15:32:25[info][99238][main][nginx-clojure embed] server started!
2023-05-18 15:32:37[error][99238][nginx-clojure-embed]server unhandled exception!
java.nio.BufferOverflowException
at java.base/java.nio.ByteBuffer.put(ByteBuffer.java:1018)
at java.base/java.nio.HeapByteBuffer.put(HeapByteBuffer.java:250)
at nginx.clojure.java.StringFacedJavaBodyFilter.decodeToString(StringFacedJavaBodyFilter.java:61)
at nginx.clojure.java.StringFacedJavaBodyFilter.doFilter(StringFacedJavaBodyFilter.java:34)
at nginx.clojure.java.NginxJavaHandler.process(NginxJavaHandler.java:114)
at nginx.clojure.NginxSimpleHandler.handleRequest(NginxSimpleHandler.java:217)
at nginx.clojure.NginxSimpleHandler.execute(NginxSimpleHandler.java:118)
at nginx.clojure.NginxClojureRT.eval(NginxClojureRT.java:1176)
at nginx.clojure.embed.NginxEmbedServer.innerStart(Native Method)
at nginx.clojure.embed.NginxEmbedServer.access$000(NginxEmbedServer.java:31)
at nginx.clojure.embed.NginxEmbedServer$1.run(NginxEmbedServer.java:323)
at java.base/java.lang.Thread.run(Thread.java:1623)
2023-05-18 15:32:37[error][99238][nginx-clojure-embed]server unhandled exception!
java.nio.BufferOverflowException
at java.base/java.nio.ByteBuffer.put(ByteBuffer.java:1018)
at java.base/java.nio.HeapByteBuffer.put(HeapByteBuffer.java:250)
at nginx.clojure.java.StringFacedJavaBodyFilter.decodeToString(StringFacedJavaBodyFilter.java:61)
at nginx.clojure.java.StringFacedJavaBodyFilter.doFilter(StringFacedJavaBodyFilter.java:34)
at nginx.clojure.java.NginxJavaHandler.process(NginxJavaHandler.java:114)
at nginx.clojure.NginxSimpleHandler.handleRequest(NginxSimpleHandler.java:217)
at nginx.clojure.NginxSimpleHandler.execute(NginxSimpleHandler.java:118)
at nginx.clojure.NginxClojureRT.eval(NginxClojureRT.java:1176)
at nginx.clojure.embed.NginxEmbedServer.innerStart(Native Method)
at nginx.clojure.embed.NginxEmbedServer.access$000(NginxEmbedServer.java:31)
at nginx.clojure.embed.NginxEmbedServer$1.run(NginxEmbedServer.java:323)
at java.base/java.lang.Thread.run(Thread.java:1623)
from nginx-clojure.
This error is caused by utf-8 decoding. Because the response body from google is compressed and can not be decoded into string directly.
The simple workaround is to let google return uncompressed body and nginx compress it before it is sent to client.
location /search {
proxy_pass https://www.google.com/search;
body_filter_type "java";
body_filter_name "org.example.replacer.GoogleLogoReplacer";
proxy_set_header Accept-Encoding "";
gzip on;
}
Another choice is to use non-string-faced body filter which decompresses the compressed binary content and converts the result to java string. The later version of nginx-clojure will improve StringFacedBodyFilter for this case.
BTW you body filter GoogleLogoReplacer is not implemented correctly. For one request the method doFilter can be invoked multiple times and at the last time the argument isLast will be true.
This is an example to get the whole body and reverse its content. StringFacedReverseBodyFilter
from nginx-clojure.
Thank you for your consistently good answers. After rewriting the code based on the example code you posted and creating nginx.conif, I was able to access it through /search. But I don't see any output, just a blank screen. And after about a minute, the following error message is displayed.
public class GoogleLogoReplacer extends StringFacedJavaBodyFilter {
@Override
protected Object[] doFilter(Map<String, Object> request, String body, boolean isLast) throws IOException {
StringBuilder whole = (StringBuilder) request.get("whole");
if (whole == null) {
request.put("whole", whole = new StringBuilder());
}
String modifiedBody = modifyGoogleLogo(body);
whole.append(modifiedBody);
if (isLast) {
return new Object[]{200, null, whole.toString()};
} else {
return new Object[] {null, null, null};
}
}
private String modifyGoogleLogo(String body) throws IOException {
Document doc = Jsoup.parse(body);
Element logo = doc.select("img.jfN4p").first();
if (logo != null) {
String newLogoUrl = "http://via.placeholder.com/400";
logo.attr("src", newLogoUrl);
}
return doc.toString();
}
}
nginx: [error] upstream timed out (60: Operation timed out) while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /search?q=d&source=hp&ei=8CFmZMedIt222roP94ebkAM&iflsig=AOEireoAAAAAZGYwAGzf7VumW15PMFaQbPrqTB2cuRi0&ved=0ahUKEwjH1YPb9v7-AhVdm1YBHffDBjIQ4dUDCAk&uact=5&oq=d&gs_lcp=Cgdnd3Mtd2l6EAMyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgsILhCABBDHARDRAzIFCAAQgAQyCwguEIAEEMcBENEDMgUIABCABDIFCAAQgAQyCwguEIAEEMcBENEDUABYAGCIAmgAcAB4AIAB4QGIAeEBkgEDMi0xmAEAoAEB&sclient=gws-wiz HTTP/1.1", upstream: "https://142.250.206.228:443/search?q=d&source=hp&ei=8CFmZMedIt222roP94ebkAM&iflsig=AOEireoAAAAAZGYwAGzf7VumW15PMFaQbPrqTB2cuRi0&ved=0ahUKEwjH1YPb9v7-AhVdm1YBHffDBjIQ4dUDCAk&uact=5&oq=d&gs_lcp=Cgdnd3Mtd2l6EAMyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgsILhCABBDHARDRAzIFCAAQgAQyCwguEIAEEMcBENEDMgUIABCABDIFCAAQgAQyCwguEIAEEMcBENEDUABYAGCIAmgAcAB4AIAB4QGIAeEBkgEDMi0xmAEAoAEB&sclient=gws-wiz", host: "localhost", referrer: "http://localhost/"
from nginx-clojure.
Is there no any other exception?
These lines of code are wrong because body is not the whole body but part of the whole body.
String modifiedBody = modifyGoogleLogo(body); // wrong!
whole.append(modifiedBody);
if (isLast) {
return new Object[]{200, null, whole.toString()};
} else {
return new Object[] {null, null, null};
}
Should be
whole.append(body);
if (isLast) {
String modifiedBody = modifyGoogleLogo(whole.toString());
return new Object[]{200, null, modifiedBody};
} else {
return new Object[] {null, null, null};
}
BTW you also need to take care of http headers passed to google , such as Host, Referer, etc , so that let google not take your proxy behavior as an exception and not block your proxy. You can use wireshark like tool to check the http packet and make it to be the same as your browser sent to google directly. Good luck!
from nginx-clojure.
Close it now. Feel free to reopen it anytime if you want to report more details.
from nginx-clojure.
Related Issues (20)
- Directives for jvm int/exit handler properties
- Enable coroutine context for invoking config method of a handler in coroutine mode
- Rewrite handlers can add/update request headers
- Dispatch incoming request to a jsp and set attribute HOT 2
- Support load-balancing handler
- Add new handler types to better support spring and spring boot
- nginx-clojure-embed need be compiled with more built-in nginx c modules HOT 1
- How to debug/test nginx-clojure handlers
- StringFacedJavaBodyFilter/StringFacedClojureBodyFilter need auto decompress body when the body is compressed.
- java.lang.RuntimeException: can not create nginx handler for name HOT 4
- CVEs in maven artifact HOT 3
- nginx 1.25.0 build error HOT 3
- Support for random user ID in containerised environments - startup failure due to POSIX method getpwuid failure
- body content sometimes (!) missing in async content handler HOT 9
- Enhance hijack API to give users a chance to manage the closing of request body
- Running Nginx Clojure in Docker prompts: jvm may be mad for wrong options HOT 3
- Error: undeclared "lcf" during installation HOT 2
- Nginx Body Filter็้ฎ้ข HOT 2
- Resolved issues have not been released HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nginx-clojure.