Configuration of Nginx:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
uWSGI FasterRouter
uwsgi --fastrouter 127.0.0.1:3030 --fastrouter-subscription-server 127.0.0.1:3131 -M
uWSGI web-app instance
uwsgi -M --subscribe-to 127.0.0.1:3131:/ --file server.py --http :8080
then HTTP GET [server ip]:80/ no response
HTTP GET [server ip]:8080/ got response
Configuration of Nginx:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
uwsgi -M --file server.py -s 127.0.0.1:3030
then HTTP GET [server ip]:80/ Got response
Do as follows. Worked. Thanks roberto for help.
Configuration of Nginx:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3030;
}
uWSGI FasterRouter
uwsgi --fastrouter 127.0.0.1:3030 --fastrouter-subscription-server 127.0.0.1:3131 -M
uWSGI web-app instance
uwsgi -M --subscribe-to 127.0.0.1:3131:[server_ip] --file server.py -s 127.0.0.1:3232
Console output
[uwsgi-subscription for pid 18957] new pool: [server_ip] (hash key: 22902)
[uwsgi-subscription for pid 18957] [server_ip] => new node: 127.0.0.1:3232
then HTTP GET [server ip]:80/ GOT response
Related
I have trouble about nginx ingress using condition
Install Nginx Ingress via helm instal (tested in both nginx-ingress-1.16 and nginx-ingress-1.36
I am try to follow
ingress nginx redirect from www to https
Setup some condition
like
nginx.ingress.kubernetes.io/configuration-snippet: |
if ( $host = "mydomain.co" ) {
rewrite ^ https://www.mydomain.co$uri permanent;
}
When apply the ingress rule, nginx ingress start reload in fail status
-------------------------------------------------------------------------------
W0602 07:35:36.244415 6 queue.go:130] requeuing vincent/demoheader-ingress, err
-------------------------------------------------------------------------------
Error: exit status 1
2020/06/02 07:35:36 [notice] 982#982: ModSecurity-nginx v1.0.0
2020/06/02 07:35:36 [emerg] 982#982: invalid condition "~" in /tmp/nginx-cfg971999838:530
nginx: [emerg] invalid condition "~" in /tmp/nginx-cfg971999838:530
nginx: configuration file /tmp/nginx-cfg971999838 test failed
My Full ingress rule
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demoheader-ingress
namespace: namespace
annotations:
kubernetes.io/ingress.class: nginx-temp
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
nginx.ingress.kubernetes.io/configuration-snippet: |
if ( $uri ~* ^/xx/(.*) ) {
rewrite ^ https://www.xxx.co permanent;
}
spec:
rules:
- host: mydomain
http:
paths:
- backend:
serviceName: header-headerv1
servicePort: 80
path: /
EOF
Any idea ?
OK i know what happen in here
I encount a wired issue for k8s apply stuff ….
While official document told you , you can apply object by this method
cat <<EOF | kubectl apply -f -
xxx
yyy
eee
EOF
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
However for ingress rule , if you under a specific condition such like this
nginx.ingress.kubernetes.io/configuration-snippet: |
if ( $host = ^mydomain ) {
rewrite ^ https://www.mydomain$uri permanent;
}
you are unable to make the nginx working again (never config reload success, it will affect the following config change)
Until you delete the ingress rule and re-apply by
kubectl apply -f the-ingress-file
docker run --rm --net=host -v $PWD/default.conf:/etc/nginx/conf.d/default.conf nginx
2019/05/12 17:02:49 [emerg] 1#1: host not found in upstream "tickethub.service.consul" in /etc/nginx/conf.d/default.conf:10
nginx: [emerg] host not found in upstream "tickethub.service.consul" in /etc/nginx/conf.d/default.conf:10
While dig shows the DNS record correctly:
dig #127.0.0.1 -p 8600 tickethub.service.consul
; <<>> DiG 9.12.3-P1 <<>> #127.0.0.1 -p 8600 tickethub.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57394
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;tickethub.service.consul. IN A
;; ANSWER SECTION:
tickethub.service.consul. 0 IN A 172.23.0.6
tickethub.service.consul. 0 IN A 172.23.0.5
tickethub.service.consul. 0 IN A 172.23.0.7
;; ADDITIONAL SECTION:
tickethub.service.consul. 0 IN TXT "consul-network-segment="
tickethub.service.consul. 0 IN TXT "consul-network-segment="
tickethub.service.consul. 0 IN TXT "consul-network-segment="
;; Query time: 0 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Sun May 12 16:58:54 GMT 2019
;; MSG SIZE rcvd: 209
And my nginx config:
server {
listen 80;
server_name localhost;
location / {
resolver 127.0.0.1:8600;
proxy_pass http://tickethub.service.consul;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
What may be the issue?
This worked when I explicitly set the DNS on the docker container to 127.0.0.1 which means Nginx is probably trying to resolve it WITHOUT using the resolver specified argh...
I think I also had to change the DNS port to 53 instead of the explicit 8600
Or something...
Probably a bunch of nginx bugs...
mic drop
It worked when I set the proxy_pass using a variable:
location / {
resolver consul;
set $endpoint tickethub.service.consul;
proxy_pass http://$endpoint/;
}
What request path is location = /bar supposed to match in Nginx?
What works fine: location /bar
Here is my nginx configuration, host file configuration, and my HTML files.
# cat /etc/nginx/sites-enabled/foo
server {
listen 80;
listen [::]:80;
server_name foo;
root /tmp/;
location /bar/ {
alias /var/www/foo/;
}
}
# cat /etc/hosts
127.0.0.1 localhost foo
127.0.1.1 debian
# cat /tmp/index.html
Hi! I am Tmp!
# cat /var/www/foo/index.html
<p>Hi! I am Index!</p>
# cat /var/www/foo/max.html
<p>Hi! I am Max!</p>
HTTP requests to the root, /bar/, and /bar/max.html produce the expected
output:
# systemctl restart nginx && curl http://foo/
Hi! I am Tmp!
# systemctl restart nginx && curl http://foo/bar/
<p>Hi! I am Index!</p>
# systemctl restart nginx && curl http://foo/bar/max.html
<p>Hi! I am Max!</p>
What does not work fine: location = /bar
Now I edit the configuration to replace location /bar with location = /bar:
# cat /etc/nginx/sites-enabled/foo
server {
listen 80;
listen [::]:80;
server_name foo;
root /tmp/;
location = /bar/ {
alias /var/www/foo/;
}
}
# systemctl restart nginx && curl http://foo/
Hi! I am Tmp!
These HTTP requests no longer work:
# systemctl restart nginx && curl http://foo/bar/
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
# tail -n 1 /var/log/nginx/error.log
2018/05/25 00:07:50 [error] 29157#29157: *1 open() "/tmp/bar/index.html" failed (2: No such file or directory), client: 127.0.0.1, server: foo, request: "GET /bar/ HTTP/1.1", host: "foo"
# systemctl restart nginx && curl http://foo/bar
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
# tail -n 1 /var/log/nginx/error.log
2018/05/25 00:08:49 [error] 29203#29203: *1 open() "/tmp/bar" failed (2: No such file or directory), client: 127.0.0.1, server: foo, request: "GET /bar HTTP/1.1", host: "foo"
# systemctl restart nginx && curl http://foo/bar/max.html
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
# tail -n 1 /var/log/nginx/error.log
2018/05/25 00:10:10 [error] 29265#29265: *1 open() "/tmp/bar/max.html" failed (2: No such file or directory), client: 127.0.0.1, server: foo, request: "GET /bar/max.html HTTP/1.1", host: "foo"
It appears that the GET requests for either /bar or /bar/ match the location = /bar/ directive? I thought these requests should have worked with this directive because http://nginx.org/en/docs/http/ngx_http_core_module.html#location mentions:
Also, using the “=” modifier it is possible to define an exact match of URI and location. If an exact match is found, the search terminates.
But as explained in my example, it does not seem to work? What kind of request would match the location = /bar directive then?
The URI /bar/ relies on the index directive to internally rewrite the URI to /bar/index.html. See this document for details.
The exact match location syntax will only match the original URI, and not the rewritten URI.
nginx will process the rewritten URI using the default location (which in your configuration, is the server context). So, the URI /bar/index.html will be searched for at /tmp/bar/index.html, and not found.
I am trying to stream a video using nginx-rtmp with rtmp protocol.
I created a index.html and embedded on it JWPlayer with the rtmp url.
On localhost, I can play the video from the browser but from another computer in same local network when I tried same thing ( open the index.html in the browser the url is http://172.16.40.162:8080 ) I get an error message.
But when I try with vlc (the rtmp url : rtmp://172.16.40.162/vod/test) it worked.
Here the code of index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>VoD Example</title>
<script src="http://jwpsrv.com/library/s7iNvOAyEeSMdQ4AfQhyIQ.js"></script>
</head>
<body>
<div id='videotest'></div>
<script type='text/javascript'>
jwplayer('videotest').setup({
file: 'rtmp://localhost/vod/test',
width: '50%',
aspectratio: '16:9'
});
</script>
</body>
</html>
the nginx.conf
#user nobody;
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
# rtmp stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# you can move stat.xsl to a different location
root /usr/local/nginx/html;
}
# rtmp control
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
rtmp {
server {
listen 1935;
notify_method get;
chunk_size 8192;
application vod {
allow play all;
wait_video on;
play /var/www/Videos;
push rtmp://localhost/vod/test;
}
}
}
I get these messages on :
acces.log
172.16.40.148 - - [16/Apr/2015:13:08:33 +0100] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
172.16.40.148 [16/Apr/2015:13:19:29 +0100] PLAY "vod" "test" "" - 382 3660906 "" "LNX 9,0,124,2" (1m 58s)
127.0.0.1 [16/Apr/2015:13:51:47 +0100] PLAY "vod" "test" "" - 483 3669724 "http://172.16.40.162:8080/" "LNX 11,2,202,457" (1m 50s)
error.log
2015/04/16 13:07:06 [notice] 3771#0: using the "epoll" event method
2015/04/16 13:07:06 [notice] 3771#0: nginx/1.5.0
2015/04/16 13:07:06 [notice] 3771#0: built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
2015/04/16 13:07:06 [notice] 3771#0: OS: Linux 2.6.32-504.12.2.el6.x86_64
2015/04/16 13:07:06 [notice] 3771#0: getrlimit(RLIMIT_NOFILE): 1024:4096
2015/04/16 13:07:06 [notice] 3772#0: start worker processes
2015/04/16 13:07:06 [notice] 3772#0: start worker process 3773
2015/04/16 13:08:41 [info] 3773#0: *3 client closed connection while waiting for request, client: 172.16.40.148, server: 0.0.0.0:8080
Information about the video I use (I executed ffmpeg -i test.flv)
Input #0, flv, from 'test.flv':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isom
encoder : Lavf56.30.100
Duration: 00:01:50.03, start: 0.060000, bitrate: 270 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 30.30 fps, 30 tbr, 1k tbn, 60 tbc
Stream #0:1: Audio: mp3, 22050 Hz, stereo, s16p, 64 kb/s
In index.html replace file: 'rtmp://localhost/vod/test' with file: 'rtmp://172.16.40.162/vod/test'.
The JWPlayer Flash will request that URL from the client machine. Using localhost will obviously not work since it looks for the stream on the same computer.
I am trying to get nginx to server some static files. I put in what I believe should be the proper directive to alias the url, but nginx is refusing to server the page. My server.conf is as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from server.fqdn.suffix
server_name server.fqdn.suffix;
location /static/ {
autoindex on;
alias /usr/share/nginx/html/poindexter/inspire/static/;
}
# Include the basic h5bp config set
include /etc/nginx/h5bp/basic.conf;
}
I assumed that this would redirect to the /usr/share/nginx/html/poindexter/inspire/static/ directory. And for the autoindex it seems to work. But when you click on a file it generates a 404 error. I took an strace and sure enough, it is not honoring the alias.
[pid 2542] <... epoll_wait resumed> {{EPOLLIN, {u32=1822502928, u64=139901792235536}}}, 512, 4294967295) = 1
[pid 2542] accept4(10, {sa_family=AF_INET, sin_port=htons(37845), sin_addr=inet_addr("198.55.232.86")}, [16], SOCK_NONBLOCK) = 24
[pid 2542] epoll_ctl(21, EPOLL_CTL_ADD, 24, {EPOLLIN|EPOLLET, {u32=1822503697, u64=139901792236305}}) = 0
[pid 2542] epoll_wait(21, {{EPOLLIN, {u32=1822503697, u64=139901792236305}}}, 512, 10000) = 1
[pid 2542] recvfrom(24, "GET /static/css/bootstrap.min.cs"..., 1024, 0, NULL, NULL) = 772
[pid 2542] open("/usr/share/nginx/html/static/css/bootstrap.min.css", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
[pid 2542] write(8, "2014/03/05 21:59:23 [error] 2542"..., 328) = 328
[pid 2542] writev(24, [{"HTTP/1.1 404 Not Found\r\nServer: "..., 172}, {"<html>\r\n<head><title>404 Not Fou"..., 116}, {"<hr><center>nginx</center>\r\n</bo"..., 46}], 3) = 334
[pid 2542] setsockopt(24, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 2542] recvfrom(24, 0x14e9240, 1024, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable
I would really appreciate any help I could get. I am very stuck.
I see several way to fix this.
1
Just add symlink from /usr/share/nginx/html/static/ to /usr/share/nginx/html/poindexter/inspire/static/ and remove alias directive. It something like aliasing on file system level.
location /static/ {
autoindex on;
}
2
Remove location ~* \.(?:css|js)$ { block.
3
Use rewrite (this solution make use the fact you static directory in inside your root)
location ^~ /static/ {
autoindex on;
rewrite ^(.+)$ /poindexter/inspire$1;
}