How to send plain text response from Nginx
You can use a return statement in Nginx to send a plain text response.
In your Nginx server entry, add
1 2 3 4 |
location ~* "^/hello/(.*)" { default_type text/plain; return 200 "Hello $1\n"; } |
Now you can access the page with the URL
1 2 3 |
boby@sok-01:~$ curl http://localhost/hello/World Hello World boby@sok-01:~$ |
Here is another example
1 2 3 4 |
location "/hello" { default_type text/plain; return 200 "Hello World\n"; } |
For any URL starting with /hello, you get the “Hello World” response.
Back to Nginx