Description
Sometimes I need to follow Effective Java to write Builder Pattern.
There are attributes, getters, Java Doc and a builder.
I wrote a Java based code generator before, I change to JavaScript based codes and put in GitHub.
import sys
import subprocess
import shlex
import re
def find_pid_by_listen_port(port):
if sys.platform == 'win32':
output = subprocess.check_output('netstat -a -n -o', universal_newlines=True)
match = re.search('.*:{0} +.* +.+ +[0-9]+'.format(port),output)
if match:
return shlex.split(match.group(0))[-1]
else:
return None
else:
raise Exception('not support platform ' + sys.platform)
pid = find_pid_by_listen_port(9160)
print(pid)
import os
import shutil
import sys
import math
import urllib.request
import subprocess
import shlex
import signal
import time
import re
from datetime import date
def http_download(download_url, download_file):
with urllib.request.urlopen(download_url) as f:
with open(download_file,'wb') as target:
filesize = int(f.getheader('Content-Length'))
wrotesize = 0
while True:
if wrotesize == int(filesize):
break
wrotesize += target.write(f.read(1024))
download_percent = math.ceil((wrotesize/filesize)*100)
print('\rDownload {0} to {1} ... {2}%'.format(download_url,download_file,download_percent),end='')
print()
def find_pid_by_listen_port(port):
if sys.platform == 'win32':
output = subprocess.check_output('netstat -a -n -o', universal_newlines=True)
match = re.search('.*:{0} +.* +.+ +[0-9]+'.format(port),output)
if match:
return shlex.split(match.group(0))[-1]
else:
return None
else:
raise Exception('not support platform ' + sys.platform)
download_url = 'http://ftp.tc.edu.tw/pub/Apache/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz'
download_file = 'd:/apache-cassandra-2.0.4-bin.tar.gz'
unzip_folder = 'd:/deploy/work/{0}/apache-cassandra-2.0.4-bin'.format(date.today().isoformat())
execute_folder = unzip_folder + '/apache-cassandra-2.0.4'
execute_path = execute_folder + '/bin/cassandra.bat'
executable = 'start cmd /c ' + execute_path
executable_argv = shlex.split(executable)
pid = find_pid_by_listen_port(9160)
if pid:
print('kill process id',pid)
os.kill(int(pid),signal.SIGTERM)
if os.path.exists('d:/deploy'):
print('Delete d:/deploy')
shutil.rmtree('d:/deploy')
http_download(download_url, download_file)
os.makedirs(unzip_folder)
print('unzip {0} to {1}'.format(download_file, unzip_folder))
shutil.unpack_archive(download_file, unzip_folder)
print('Execute',execute_path)
subprocess.Popen(executable_argv,shell=True)
import sys
import math
import urllib.request
def http_download(download_url, download_file):
with urllib.request.urlopen(download_url) as f:
with open(download_file,'wb') as target:
filesize = int(f.getheader('Content-Length'))
wrotesize = 0
while True:
if wrotesize == int(filesize):
break
wrotesize += target.write(f.read(1024))
download_percent = math.ceil((wrotesize/filesize)*100)
print('\rDownload {0} to {1} ... {2}%'.format(download_url,download_file,download_percent),end='')
if len(sys.argv) < 3:
print('Usage: {0} download_url download_file'.format(sys.argv[0]))
else:
download_url = sys.argv[1]
download_file = sys.argv[2]
http_download(download_url, download_file)
import urllib.request
with urllib.request.urlopen('http://ftp.tc.edu.tw/pub/Apache/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz') as f:
with open('d:/apache-cassandra-2.0.4-bin.tar.gz','wb') as target:
target.write(f.read())
import urllib.request
with urllib.request.urlopen('http://ftp.tc.edu.tw/pub/Apache/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz') as f:
with open('d:/apache-cassandra-2.0.4-bin.tar.gz','wb') as target:
filesize = f.getheader('Content-Length')
wrotesize = 0
while True:
if wrotesize == int(filesize):
break
wrotesize += target.write(f.read(1024))
print('download...',wrotesize,'of',filesize)
import urllib.request
pwdmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
pwdmgr.add_password(None,'http://mvn.company.site','myid','mypw')
auth_handler = urllib.request.HTTPBasicAuthHandler(pwdmgr)
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
with urllib.request.urlopen('http://mvn.company.site/downloadfile.zip') as f:
with open('d:/downloadfile.zip','wb') as target:
target.write(f.read())
import shutil unzipfile_folder = 'd:/unziptarget' archive_name = 'd:/ziptarget/test' root_dir = 'd:/nginx-1.4.3' archive_path = shutil.make_archive(archive_name, 'zip', root_dir) shutil.unpack_archive(archive_path, unzipfile_folder)
for i in range(5):
print(i)
0 1 2 3 4
class NumberIterator:
def __init__(self, max):
self.max = max
self.current = 0
def __iter__(self):
print('iter is called. max=',self.max)
return self
def __next__(self):
print('next is called, current=', self.current, ', max=', self.max)
if ( self.current == self.max ):
raise StopIteration
self.current += 1
return self.current
it = NumberIterator(5)
# "for" statement will call iter() of NumberIterator
# so 'iter is called. max=' will be printed
for i in it:
print(i) #print 1 ~ 5
# there is no "for" statement, so 'iter is called. max=' won't be printed
it = NumberIterator(4)
print(next(it))
print(next(it))
print(next(it))
print(next(it))
print(next(it)) #StopIteration
d:\workspace_python>python test.py iter is called. max= 5 next is called, current= 0 , max= 5 1 next is called, current= 1 , max= 5 2 next is called, current= 2 , max= 5 3 next is called, current= 3 , max= 5 4 next is called, current= 4 , max= 5 5 next is called, current= 5 , max= 5 next is called, current= 0 , max= 4 1 next is called, current= 1 , max= 4 2 next is called, current= 2 , max= 4 3 next is called, current= 3 , max= 4 4 next is called, current= 4 , max= 4 Traceback (most recent call last): File "test.py", line 27, inprint(next(it)) #StopIteration File "test.py", line 11, in __next__ raise StopIteration StopIteration
def test_yield():
i = 0
print('before the first yield',i)
yield i
print('after the first yield',i)
i += 1
print('before the second yield',i)
yield i
print('after the second yield',i)
i += 1
for i in range(3):
print('before yield in for stmt')
yield i**2
print('after yield in for stmt')
for i in test_yield():
print(i)
d:\workspace_python>python test.py before the first yield 0 0 after the first yield 0 before the second yield 1 1 after the second yield 1 before yield in for stmt 0 after yield in for stmt before yield in for stmt 1 after yield in for stmt before yield in for stmt 4 after yield in for stmt
package test;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;
public class TestIO {
public static void main(String[] params) throws IOException {
Charset cs = Charset.forName("utf-8");
Path path = Paths.get("d:/", "test.txt");
List lines = Arrays.asList("line1", "line2", "line3");
Files.write(path, lines, cs, StandardOpenOption.TRUNCATE_EXISTING);
List readLines = Files.readAllLines(path, cs);
System.out.println(readLines);
}
}
package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.UUID;
public class TestIO {
public static void main(String[] params) throws IOException {
Charset cs = Charset.forName("utf-8");
Path path = Paths.get("d:/", "test.txt");
int wLineCnt = 25000000;
try (
BufferedWriter writer = Files.newBufferedWriter(
path, cs, StandardOpenOption.TRUNCATE_EXISTING)) {
for ( int i = 0; i < wLineCnt; i++ ) {
writer.write(i + ":" + UUID.randomUUID().toString() + "\n");
}
writer.flush();
}
try (BufferedReader reader = Files.newBufferedReader(path, cs)) {
int rLineCnt = 0;
String line = null;
while ((line = reader.readLine()) != null) {
int num = Integer.valueOf(line.substring(0, line.indexOf(":")));
if ( rLineCnt++ != num ) {
throw new RuntimeException(
"not equal! " + num + "," + rLineCnt);
}
}
if ( rLineCnt != wLineCnt ) {
throw new RuntimeException(
"not equal! " + wLineCnt + "," + rLineCnt);
}
}
System.out.println("done");
}
}
package test;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class TestIO {
public static void main(String[] params) throws IOException {
for (Path path: FileSystems.getDefault().getRootDirectories()) {
System.out.println(path); //列出 C:/ & D:/ ..etc
}
}
}
package test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class TestIO {
public static void main(String[] params) throws IOException {
Files.createDirectories(Paths.get("d:/test1/test2/test3/test4"));
}
}
DirectoryStream is created.package test;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class TestIO {
public static void main(String[] params) throws IOException {
long start = System.currentTimeMillis();
createFolders();
System.out.println("spend " + (System.currentTimeMillis() - start)
+ " millis to create folders");
start = System.currentTimeMillis();
System.out.println(listFoldersNIO(Paths.get("d:/test")));
System.out.println("spend " + (System.currentTimeMillis() - start)
+ " millis to list folders (NIO)");
start = System.currentTimeMillis();
System.out.println(listFoldersIO(Paths.get("d:/test").toFile()));
System.out.println("spend " + (System.currentTimeMillis() - start)
+ " millis to list folders (IO)");
}
private static void createFolders() throws IOException {
for ( int i = 0; i < 1000000; i++ ) {
Files.createDirectories(Paths.get("d:/test/test" + i));
System.out.println(i);
}
System.out.println("done");
}
private static int listFoldersIO(File folder) {
int cnt = 0;
for ( String child: folder.list() ) {
new File(child);
cnt++;
}
return cnt;
}
private static int listFoldersNIO(Path path) throws IOException {
int cnt = 0;
try ( DirectoryStream dirStream = Files.newDirectoryStream(path) ) {
for ( Path child: dirStream ) {
child.toFile();
cnt++;
}
}
return cnt;
}
}
* but crosses directory boundaries" 讓我有錯誤的期望以為只要 Files.newDirectoryStream(p, "**/*.{java,jar}") 就可以列舉全部的檔案, 測試結果不行..package test;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class TestIO {
public static void main(String[] params) throws IOException {
listAll(Paths.get("d:\\Isaac"), "*.{java,jar}");
}
private static void listAll(Path p, String globPattern) throws IOException {
try (
DirectoryStream<Path> s = Files.newDirectoryStream(p, globPattern)
) {
for ( Path c: s ) {
System.out.println(c);
}
}
try (DirectoryStream<Path> s = Files.newDirectoryStream(p)) {
for ( Path c: s ) {
if ( Files.isDirectory(c, LinkOption.NOFOLLOW_LINKS) ) {
listAll(c, globPattern);
}
}
}
}
}
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
public class TestIO {
public static void main(String[] params) throws IOException {
listAll(Paths.get("d:\\activemq-parent-5.8.0-source-release"), "Queue");
}
private static void listAll(Path p, final String containTxt)
throws IOException {
DirectoryStream.Filter<Path> f = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
if ( Files.isDirectory(entry, LinkOption.NOFOLLOW_LINKS)
|| !entry.toString().endsWith(".java") ) {
return false;
}
try (BufferedReader reader = Files.newBufferedReader(
entry, Charset.forName("UTF8"))) {
String line = null;
while ( (line = reader.readLine()) != null ) {
if ( line.contains(containTxt) ) {
return true;
}
}
}
return false;
}
};
try (DirectoryStream<Path> s = Files.newDirectoryStream(p, f)) {
for ( Path c: s ) {
System.out.println("match " + c);
}
}
try (DirectoryStream<Path> s = Files.newDirectoryStream(p)) {
for ( Path c: s ) {
if ( Files.isDirectory(c, LinkOption.NOFOLLOW_LINKS) ) {
listAll(c, containTxt);
}
}
}
}
}
package test;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class TestIO {
public static void main(String[] params) throws IOException {
Path p = Paths.get("d:/Isaac");
FileVisitor<Path> f = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,BasicFileAttributes attrs) throws IOException {
String filepath = file.toString();
if ( filepath.endsWith(".java") || filepath.endsWith(".jar") ) {
System.out.println(filepath);
}
return super.visitFile(file, attrs);
}
};
Files.walkFileTree(p, f);
}
}
package test;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class TestIO {
public static void main(String[] params) throws Throwable {
final PathMatcher matcher =
FileSystems.getDefault().getPathMatcher("glob:*.{java,jar}");
Files.walkFileTree(Paths.get("d:/Isaac"), new SimpleFileVisitor<Path>(){
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
if ( matcher.matches(file.getFileName()) ) {
System.out.println("match " + file);
}
return super.visitFile(file, attrs);
}
});
}
}
package test;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class TestIO {
public static void main(String[] params) throws Throwable {
ExecutorService e = Executors.newSingleThreadExecutor();
Path path = Paths.get("d:/Isaac");
try (final WatchService w = FileSystems.getDefault().newWatchService()) {
path.register(w, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
e.execute(new Runnable(){
@Override
public void run() {
while (true) {
try {
WatchKey k = w.take();
for ( WatchEvent<?> e: k.pollEvents() ) {
@SuppressWarnings("unchecked")
WatchEvent<Path> pathEvent = (WatchEvent<Path>)e;
Path path = pathEvent.context();
System.out.println(pathEvent.kind() + ":" path);
if (!k.reset()) {
break;
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}});
TimeUnit.DAYS.sleep(1);
}
}
}
package test;
public class TestStringSwitch {
public static void main(String[] params) {
inJDK7("abc");
inJDK6("abc");
}
private static void inJDK7(String txt) {
switch (txt) {
case "a":
System.out.println("a");
break;
case "b":
System.out.println("b");
break;
case "abc":
System.out.println("abc");
break;
default:
System.out.println("not match");
}
}
private static void inJDK6(String txt) {
if ( "a".equals(txt) ) {
System.out.println("a");
} else if ( "b".equals(txt) ) {
System.out.println("b");
} else if ( "abc".equals(txt) ) {
System.out.println("abc");
} else {
System.out.println("not match");
}
}
}
package test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestGenericDeclare {
public static void main(String[] params) {
// JDK6
Map> map0 = new HashMap>();
// JDK7
Map> map1 = new HashMap<>();
}
}
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
public class TestAutoClosable {
public static void main(String[] params) throws IOException {
File file1 = new File("d:/test.txt");
File file2 = new File("d:/test2.txt");
inJDK6(file1,file2);
inJDK7(file1,file2);
}
private static void inJDK7(File file1, File file2) throws IOException {
try (
FileReader fileReader1 = new FileReader(file1);
FileReader fileReader2 = new FileReader(file2);
BufferedReader reader1 = new MyBufferedReader("7 reader1", fileReader1);
BufferedReader reader2 = new MyBufferedReader("7 reader2", fileReader2);
) {
System.out.println(reader1.readLine());
System.out.println(reader2.readLine());
}
}
private static void inJDK6(File file1, File file2) {
BufferedReader reader1 = null;
BufferedReader reader2 = null;
try {
reader1 = new MyBufferedReader("JDK6 style reader1", new FileReader(file1));
reader2 = new MyBufferedReader("JDK6 style reader2", new FileReader(file2));
System.out.println(reader1.readLine());
System.out.println(reader2.readLine());
} catch(Throwable ex) {
ex.printStackTrace();
} finally {
if ( reader1 != null ) {
try {
reader1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if ( reader2 != null ) {
try {
reader2.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static class MyBufferedReader extends BufferedReader {
private final String name;
public MyBufferedReader(String name, Reader reader) {
super(reader);
this.name = name;
}
@Override
public void close() throws IOException {
super.close();
System.out.println("close " + name);
}
}
}
package test;
public class TestHandleMoreThanOneException {
public static void main(String[] params) throws Exception {
rethrowEx("3");
}
private static void rethrowEx(String exNum) throws Ex1,Ex2 {
try {
throwEx(exNum);
} catch (Ex1 | Ex2 e) {
throw e;
} catch (Exception e) {
throw e;
}
}
private static void throwEx(String exNum) throws Ex1, Ex2 {
switch (exNum) {
case "1":
throw new Ex1();
case "2":
throw new Ex2();
default:
System.out.println("not match");
}
}
public static class Ex1 extends Exception {}
public static class Ex2 extends Exception {}
}
>>> import json
>>> m = {'a':1,'b':[1,2,3,4,5,6]}
>>> with open('d:/test.txt','w') as f:
json.dump(m,f)
>>> with open('d:/test.txt') as f:
f.readline()
'{"a": 1, "b": [1, 2, 3, 4, 5, 6]}'
>>> with open('d:/test.txt') as f:
x = json.load(f)
>>> x
{'a': 1, 'b': [1, 2, 3, 4, 5, 6]}
>>>
{"a": 1, "b": [1, 2, 3, 4, 5, 6]}
試著作一次if __name__ == "__main__": import sys fib(int(sys.argv[1]))
def say(words):
print(words)
if __name__ == '__main__':
import sys
say(sys.argv[1])
print(__name__,sys.argv[0])
C:\Python33>python.exe say.py hello hello __main__ say.py
>>> words = ['a','b','cc']
>>> for w in words:
if len(w)>1:
print('insert',w)
words.insert(0,w)
for w in words:
for w in words[:]:
>>> words is words True >>> words is words[:] False果然沒錯.
package test;
import java.util.Arrays;
import java.util.List;
public class TestIter {
public static void main(String[] params) {
List words = Arrays.asList("a","b","cc");
for (String w: words) {
if (w.length() > 1) {
System.out.println("insert " + w);
words.add(w);
}
}
}
}
會報錯
insert cc
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)
at test.TestIter.main(TestIter.java:13)
package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class TestIter {
public static void main(String[] params) {
List words = Arrays.asList("a","b","cc");
List copyWords = new ArrayList(words);
for (String w: words) {
if (w.length() > 1) {
System.out.println("insert " + w);
copyWords.add(0,w);
}
}
System.out.println(words);
System.out.println(copyWords);
}
}
def print_pascal(row_cnt):
pascal = []
for row in range(row_cnt):
cols = []
for col in range(row+1):
if row == 0:
cols.append(1)
elif col == 0 or col == row:
cols.append(1)
else:
val = pascal[row-1][col-1]+pascal[row-1][col];
cols.append(val)
pascal.append(cols)
for row in pascal:
for i in range(row_cnt-len(row)):
print('%5s' %'',end='')
for col in row:
print('%5d' %col,end='%5s' %'')
print()
>>> print_pascal(6)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
D:\nginx-1.4.3\nginx.exe D:\nginx-1.4.3\conf\nginx.conf D:\nginx-1.4.3\testhtml\testhtml.html D:\nginx-1.4.3\internal\internal.html D:\nginx-1.4.3\internal\service\service.html D:\nginx-1.4.3\internal\service\serviceA\serviceA.html
server {
listen 8080;
server_name 127.0.0.1;
root testhtml;
location / {
index testhtml.html;
}
location /service/ {
proxy_pass http://127.0.0.1:12345;
}
}
server {
listen 12345;
server_name 127.0.0.1;
root internal;
location / {
index internal.html;
}
location /service/ {
index service.html;
}
}
GET /service/ HTTP/1.1 Host: 127.0.0.1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 30 Oct 2013 23:25:39 GMT Content-Type: text/html Content-Length: 20 Connection: close Last-Modified: Wed, 30 Oct 2013 23:25:34 GMT ETag: "5271956e-14" Accept-Ranges: bytes This is service.html
2013/10/31 07:25:39 [debug] 4348#6716: *139 http script copy: "Host: " 2013/10/31 07:25:39 [debug] 4348#6716: *139 http script var: "127.0.0.1:12345" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http script copy: " " 2013/10/31 07:25:39 [debug] 4348#6716: *139 http script copy: "Connection: close " 2013/10/31 07:25:39 [debug] 4348#6716: *139 http script copy: "" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http script copy: "" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http proxy header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http proxy header: "Accept: */*" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http proxy header: "Accept-Encoding: gzip,deflate,sdch" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http proxy header: "Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4" 2013/10/31 07:25:39 [debug] 4348#6716: *139 http proxy header: "GET /service/ HTTP/1.0 Host: 127.0.0.1:12345 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
"
GET /service/serviceA/serviceA.html HTTP/1.1 Host: 127.0.0.1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 30 Oct 2013 23:33:12 GMT Content-Type: text/html Content-Length: 21 Connection: close Last-Modified: Wed, 30 Oct 2013 23:33:08 GMT ETag: "52719734-15" Accept-Ranges: bytes This is serviceA.html
D:\nginx-1.4.3\nginx.exe D:\nginx-1.4.3\conf\nginx.conf D:\nginx-1.4.3\testhtml\data\www\index.html D:\nginx-1.4.3\testhtml\data\images
Hello!, This is testhtml\data\www\index.html
server {
listen 8080;
server_name 127.0.0.1;
location / {
root testhtml/data/www;
index index.html;
}
}
GET / HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sun, 27 Oct 2013 23:22:23 GMT Content-Type: text/html Content-Length: 44 Last-Modified: Sun, 27 Oct 2013 23:22:19 GMT Connection: close ETag: "526da02b-2c" Accept-Ranges: bytes Hello!, This is testhtml\data\www\index.html
D:\nginx-1.4.3\testhtml\data\www\www.html D:\nginx-1.4.3\testhtml\data\data.html D:\nginx-1.4.3\conf\nginx.conf
Hello!, This is data.html
Hello!, This is www.html
server {
listen 8080;
server_name 127.0.0.1;
location / {
root testhtml/data/www;
index www.html;
}
location /data/ {
root testhtml;
index data.html;
}
}
GET / HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 28 Oct 2013 15:33:05 GMT Content-Type: text/html Content-Length: 24 Last-Modified: Sun, 27 Oct 2013 23:32:37 GMT Connection: close ETag: "526da295-18" Accept-Ranges: bytes Hello!, This is www.html
GET /data/ HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 28 Oct 2013 15:49:13 GMT Content-Type: text/html Content-Length: 25 Last-Modified: Sun, 27 Oct 2013 23:32:15 GMT Connection: close ETag: "526da27f-19" Accept-Ranges: bytes Hello!, This is data.html
GET /data/www/www.html HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 28 Oct 2013 15:50:23 GMT Content-Type: text/html Content-Length: 24 Last-Modified: Sun, 27 Oct 2013 23:32:37 GMT Connection: close ETag: "526da295-18" Accept-Ranges: bytes Hello!, This is www.html
D:\nginx-1.4.3\testhtml\testhtml.html D:\nginx-1.4.3\testhtml\data\data.html D:\nginx-1.4.3\conf\nginx.conf
Hello!, This is data.html
Hello!, This is testhtml.html
server {
listen 8080;
server_name 127.0.0.1;
root testhtml;
location / {
index testhtml.html;
}
location /data/ {
index data.html;
}
}
GET / HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 28 Oct 2013 23:51:46 GMT Content-Type: text/html Content-Length: 29 Last-Modified: Mon, 28 Oct 2013 23:45:17 GMT Connection: close ETag: "526ef70d-1d" Accept-Ranges: bytes Hello!, This is testhtml.html
GET /data/ HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 28 Oct 2013 23:52:29 GMT Content-Type: text/html Content-Length: 25 Last-Modified: Sun, 27 Oct 2013 23:32:15 GMT Connection: close ETag: "526da27f-19" Accept-Ranges: bytes Hello!, This is data.html
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'www.*';
}
}
server {
listen 127.0.0.1:8080;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
GET /test HTTP/1.1 Host: server1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 23 Oct 2013 22:36:16 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server1
server {
listen 127.0.0.1:8080;
server_name *.server1.*;
location /test {
return 200 '*.server1';
}
}
nginx: [emerg] invalid server name or wildcard "*.server1.*" on 127.0.0.1:8080
server {
listen 127.0.0.1:8080;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'server1.*';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
GET /test HTTP/1.1
Host: www.server1
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK
Server: nginx/1.4.3
Date: Wed, 23 Oct 2013 22:58:48 GMT
Content-Type: application/octet-stream
Content-Length: 9
Connection: close
*.server1
GET /test HTTP/1.1
Host: www.abc.qqq.hahaha.server1
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK
Server: nginx/1.4.3
Date: Wed, 23 Oct 2013 22:58:48 GMT
Content-Type: application/octet-stream
Content-Length: 9
Connection: close
*.server1
server {
listen 127.0.0.1:8080;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name *.hahaha.server1;
location /test {
return 200 '*.hahaha.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'www.*';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
GET /test HTTP/1.1
Host: www.abc.qqq.hahaha.server1
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK
Server: nginx/1.4.3
Date: Wed, 23 Oct 2013 23:07:06 GMT
Content-Type: application/octet-stream
Content-Length: 16
Connection: close
*.hahaha.server1
server {
listen 127.0.0.1:8080;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name *.hahaha.server1;
location /test {
return 200 '*.hahaha.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'www.*';
}
}
server {
listen 127.0.0.1:8080;
server_name www.abc.qqq.*;
location /test {
return 200 'www.abc.qqq.*';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
GET /test HTTP/1.1
Host: www.abc.qqq.hahaha.server1.net
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK
Server: nginx/1.4.3
Date: Wed, 23 Oct 2013 23:13:59 GMT
Content-Type: application/octet-stream
Content-Length: 13
Connection: close
www.abc.qqq.*
server {
listen 127.0.0.1:8080;
server_name *.server1.*;
location /test {
return 200 '*.server1.*';
}
}
nginx: [emerg] invalid server name or wildcard "*.server1.*" on 127.0.0.1:8080
server {
listen 127.0.0.1:8080;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name *.hahaha.server1;
location /test {
return 200 '*.hahaha.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'www.*';
}
}
server {
listen 127.0.0.1:8080;
server_name www.abc.qqq.*;
location /test {
return 200 'www.abc.qqq.*';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
server {
listen 127.0.0.1:8080 default;
server_name ~.*abc\.qqq\.hahaha\.server1.*;
location /test {
return 200 '~.*abc\.qqq\.hahaha\.server1.*';
}
}
GET /test HTTP/1.1 Host: xyz.abc.qqq.hahaha.server1.net Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 23 Oct 2013 23:37:15 GMT Content-Type: application/octet-stream Content-Length: 13 Connection: close ~.*server1.*
server {
listen 127.0.0.1:8080;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name *.hahaha.server1;
location /test {
return 200 '*.hahaha.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'www.*';
}
}
server {
listen 127.0.0.1:8080;
server_name www.abc.qqq.*;
location /test {
return 200 'www.abc.qqq.*';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name ~.*abc\.qqq\.hahaha\.server1.*;
location /test {
return 200 '~.*abc\.qqq\.hahaha\.server1.*';
}
}
server {
listen 127.0.0.1:8080;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
GET /test HTTP/1.1 Host: xyz.abc.qqq.hahaha.server1.net Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 23 Oct 2013 23:39:05 GMT Content-Type: application/octet-stream Content-Length: 31 Connection: close ~.*abc\.qqq\.hahaha\.server1.*
server {
listen 127.0.0.1:8080 default;
server_name ~.*abc\.q{3}\.hahaha\.server1.*;
location /test {
return 200 '~.*abc\.q{3}\.hahaha\.server1.*';
}
}
nginx: [emerg] directive "server_name" is not terminated by ";" in C:\Users\isaac\Downloads\nginx-1.4.3\nginx-1.4.3/conf/nginx.conf:72
server {
listen 127.0.0.1:8080;
server_name *.server1;
location /test {
return 200 '*.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name *.hahaha.server1;
location /test {
return 200 '*.hahaha.server1';
}
}
server {
listen 127.0.0.1:8080;
server_name www.*;
location /test {
return 200 'www.*';
}
}
server {
listen 127.0.0.1:8080;
server_name www.abc.qqq.*;
location /test {
return 200 'www.abc.qqq.*';
}
}
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name "~.*abc\.q{3}\.hahaha\.server1.*";
location /test {
return 200 '~.*abc\.q{3}\.hahaha\.server1.*';
}
}
server {
listen 127.0.0.1:8080;
server_name ~.*server1.*;
location /test {
return 200 '~.*server1.*';
}
}
GET /test HTTP/1.1 Host: xyz.abc.qqq.hahaha.server1.net Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK
Server: nginx/1.4.3
Date: Wed, 23 Oct 2013 23:51:10 GMT
Content-Type: application/octet-stream
Content-Length: 31
Connection: close
~.*abc\.q{3}\.hahaha\.server1.*
server {
listen 127.0.0.1:8080;
server_name ~(?P.*)\.server1.*;
location /test {
return 200 'you request ${serviceName} service, service_name pattern ~(?P.*)\.server1.* is Python compatible syntax, supported since PCRE-4.0';
}
}
server {
listen 127.0.0.1:8081;
server_name ~(?.*)\.server1.*;
location /test {
return 200 'you request ${serviceName} service, service_name pattern ~(?.*)\.server1.* is Perl 5.10 compatible syntax, supported since PCRE-7.0';
}
}
GET /test HTTP/1.1 Host: tw.mail.server1.net Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sun, 27 Oct 2013 05:14:53 GMT Content-Type: application/octet-stream Content-Length: 135 Connection: close you request tw.mail service, service_name pattern ~(?P.*)\.server1.* is Python compatible syntax, supported since PCRE-4.0
GET /test HTTP/1.1 Host: tw.mail.server1.net Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sun, 27 Oct 2013 05:16:06 GMT Content-Type: application/octet-stream Content-Length: 137 Connection: close you request tw.mail service, service_name pattern ~(?.*)\.server1.* is Perl 5.10 compatible syntax, supported since PCRE-7.0
server { listen 127.0.0.1:8080; server_name ~(.*)\.(.*); location /test { return 200 'you request service "$1" in domain "$2"'; } }
GET /test HTTP/1.1 Host: mail.server1 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sun, 27 Oct 2013 05:22:37 GMT Content-Type: application/octet-stream Content-Length: 46 Connection: close you request service "mail" in domain "server1"
server { listen 127.0.0.1:8080; location /test { return 200 'you request ${hostname}'; } }
GET /test HTTP/1.1 Host: 127.0.0.1 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sun, 27 Oct 2013 05:41:41 GMT Content-Type: application/octet-stream Content-Length: 20 Connection: close you request isaac-pc
server {
listen 8080;
server_name _;
location / {
return 200 'you request ${http_Host}';
}
}
GET / HTTP/1.1 Host: abc:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 30 Oct 2013 23:39:30 GMT Content-Type: application/octet-stream Content-Length: 20 Connection: close you request abc:8080
server {
listen 8080;
server_name --;
location / {
return 200 'you request ${http_Host}';
}
}
GET / HTTP/1.1 Host: abc:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 30 Oct 2013 23:39:30 GMT Content-Type: application/octet-stream Content-Length: 20 Connection: close you request abc:8080
server {
listen 8080;
server_name !@#;
location / {
return 200 'you request ${http_Host}';
}
}
GET / HTTP/1.1 Host: abc:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Wed, 30 Oct 2013 23:39:30 GMT Content-Type: application/octet-stream Content-Length: 20 Connection: close you request abc:8080
server {
listen 8080;
server_name example.com;
location /test {
return 200 'example.com';
}
}
server {
listen 8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 8080;
server_name server2;
location /test {
return 200 'server2';
}
}
GET /test HTTP/1.1 Host: server2:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 23:04:24 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server2
server {
listen 8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 8080;
server_name server2;
location /test {
return 200 'server2';
}
}
GET /test HTTP/1.1 Host: 127.0.0.1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 22:55:05 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server1
server {
listen 8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 8080 default;
server_name server2;
location /test {
return 200 'server2';
}
}
GET /test HTTP/1.1 Host: 127.0.0.1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 22:59:23 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server2
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080;
server_name server2;
location /test {
return 200 'server2';
}
}
server {
listen 127.0.0.2:8081;
server_name server3;
location /test {
return 200 'server3';
}
}
server {
listen 127.0.0.2:8081;
server_name server4;
location /test {
return 200 'server4';
}
}
GET /test HTTP/1.1 Host: localhost Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 23:20:33 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server1
GET /test HTTP/1.1 Host: localhost Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 23:21:52 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server3
server {
listen 127.0.0.1:8080;
server_name server1;
location /test {
return 200 'server1';
}
}
server {
listen 127.0.0.1:8080 default;
server_name server2;
location /test {
return 200 'server2';
}
}
server {
listen 127.0.0.2:8081;
server_name server3;
location /test {
return 200 'server3';
}
}
server {
listen 127.0.0.2:8081 default;
server_name server4;
location /test {
return 200 'server4';
}
}
GET /test HTTP/1.1 Host: localhost Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 23:20:33 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server2
GET /test HTTP/1.1 Host: localhost Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Mon, 21 Oct 2013 23:21:52 GMT Content-Type: application/octet-stream Content-Length: 7 Connection: close server4
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
set $foo "hello";
rewrite ^ /test2;
}
location /test2 {
return 200 "${foo} world";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
return 200 "Your address:${remote_addr}:${remote_port}. nginx version:${nginx_version}. nginx pid:${pid}";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
C:\nginx-1.4.3>tasklist /fi "imagename eq nginx.exe" 映像名稱 PID 工作階段名稱 工作階段 # RAM使用量 ========================= ======== ================ =========== ============ nginx.exe 4044 Console 1 6,044 K nginx.exe 8132 Console 1 6,400 K
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
return 200 "The parameter abc value: ${arg_abc}";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
return 200 "The header 'abc' value: ${http_abc}";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
GET /test HTTP/1.1 Host: 127.0.0.1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4 ABC: 123
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sat, 19 Oct 2013 14:03:40 GMT Content-Type: application/octet-stream Content-Length: 27 Connection: close The header 'abc' value: 123
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
return 200 "The cookie 'abc' value: ${cookie_abc}";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
GET /test HTTP/1.1 Host: 127.0.0.1:8080 Connection: close User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: ABC=123
HTTP/1.1 200 OK Server: nginx/1.4.3 Date: Sat, 19 Oct 2013 14:09:30 GMT Content-Type: application/octet-stream Content-Length: 27 Connection: close The cookie 'abc' value: 123
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
set $foo "hello world";
return 200 "$foo";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /test {
set $foo "hello";
return 200 "${foo} world";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
GET /test HTTP/1.1 Host: 127.0.0.1:8080 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Accept: */* Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP/1.1 200 OK
Server: nginx/1.4.3
Date: Sat, 19 Oct 2013 11:12:59 GMT
Content-Type: application/octet-stream
Content-Length: 11
Connection: keep-alive
hello world
Recently, I benchmarked vLLM on a GPU to better understand how much throughput can realistically be expected in an LLM serving setup. One ...