i run a streaming service via Nginx server ,
i want to run the stream ( format m3u8) via only 1 domain
server {
listen 80;
server_name www.mydomain.com;
if ($host != "www.mydomain.com") {
return 403;
}
}
here when i test the link for example : http://ip_server_stream/live/1.playlist.m3u8 on browser it give Forbideen 403 error on all domains
if i put only
server {
listen 80;
server_name www.mydomain.com;
}
it works on all domains and VLC
i want only the link http://ip_server_stream/live/1.playlist.m3u8 works on www.mydomain.com not other domains or vlc
my nginx version is 1.7.5
this is my nginx confige file
this is my config file , it give error 403 on all domains even if i have an IF condition
worker_processes 8;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1991;
allow play all;
application live {
allow play all;
live on;
hls on;
hls_nested on;
hls_path /HLS/live;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
if ($http_host != "www.mydomain.com") {
return 403;
}
location /live {
index index.html index.htm;
types {
application/vnd.apple.mpegurl m3u8;
}
alias /HLS/live;
add_header Cache-Control no-cache;
}
location / {
root html;
index index.html index.htm;
}
}
}
Let's make two servers. One of them is dummy just return 403 response.
http {
# dummy server.
server {
listen 80 default_server;
location / {
return 403;
}
}
# main server.
server {
listen 80;
server_name www.mydomain.com;
# PLEASE WRITE YOUR CONFIGURATION.
}
}
Try this.
if ($http_host != "www.mydomain.com") {
return 403;
}
Related
Forms work great when not on SSL.
But on on SSL when submitting form the page simply refreshes, no redirect or changes saved.
I am using Flask-Forms and using url_for in the form action parameter.
How do I solve this issue?
Nginx Conf:
server {
server_name www.example.com;
location /static {
alias /home/admin/app/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
#ssl stuff
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
}
listen 80;
server_name www.example.com
return 404;
}
I have setup a docker environment for testing nginx reverse proxy.
Instead of setting up a subdomain for every backend, i would like to have 1 subdomain with a location pointing to the individual backend:
while this works as expected:
server {
listen 80;
server_name dashboard.test.lan;
location / {
proxy_pass http://172.17.0.1:82;
}
}
server {
listen 80;
server_name gitlab.test.lan;
location / {
proxy_pass http://172.17.0.1:83;
}
}
server {
listen 80;
server_name portainer.test.lan;
location / {
proxy_pass https://172.17.0.1:9443;
}
}
...this does not work:
server {
listen 80;
server_name proxy.test.lan;
location /dashboard {
proxy_pass http://172.17.0.1:82;
}
location /gitlab {
proxy_pass http://172.17.0.1:83;
}
location /portainer {
proxy_pass https://172.17.0.1:9443;
}
}
Maybe you guys can give me a hint or explanation why this does not work.
On my server two types of services are running. some services are normal and need ssl certificate but one service should use pass through. I read the document and what I understood is that I need to create a stream on a new port. if I am using 443 for ssl then I can't use it for passthrough.so created a pass through stream on a new port 8443. Every thing works fine but for passthrough service I need to enter the port along with url e.g https://production-server:8443. I want it like
https://production-server:8443 -> https://production-server
so my question is can we reroute a request in nginx ? here is my configuration
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream unsecure{
server prod-exec:8040 ;
keepalive 64;
}
upstream secure {
server prod-exec:9001
keepalive 64;
}
server {
listen 80;
server_name ServerA;
access_log C:/nginx-1.20.1/logs/access.log upstreamlog;
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
proxy_pass http://unsecure/services;
}
location /services/countingservice {
proxy_pass http://unsecure;
}
}
location /services/balancingservice {
proxy_pass http://unsecure;
}
}
server {
listen 443 ssl;
server_name server-A:443;
access_log C:/software/nginx-1.20.1/logs/access.log upstreamlog;
ssl_certificate C:\\nginx-1.20.1\\ssl\\certificate.crt;
ssl_certificate_key C:\\nginx-1.20.1\\ssl\\certificate_key.key;
error_page 401 /test_401.html;
location = /test_401.html {
root /C:/nginx-1.20.1/html;
internal;
}
location / {
proxy_pass https://secure/services;
}
location /services/countingservice {
proxy_pass http://secure;
}
}
location /services/balancingservice {
proxy_pass http://secure;
}
}
stream {
access_log C:/nginx-1.20.1/logs/access.log main;
upstream passthrough_test {
server prod-exec:9001 max_fails=2 fail_timeout=180s ;
# Definition of Nginx server (URL + Port) for Application 1
server {
listen server A: 84443;
listen 84443;
proxy_pass passthrough_test;
proxy_next_upstream on;
}
}
I don't want to add port with URL for pass through. so if I config the passthrough on 443 can nginx filter the request by recognizing it's pattern?
or is there any other way?
Any help would be appreciated. Thanks in Advance.
This is my nginx conf file.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:9000;
}
location /some/directory {
proxy_pass http://localhost:8998;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://localhost:8999;
}
}
For some reason example.com and example2.com are working, but example.com/some/directory is not.
localhost:9000 & localhost:8999: are harp.js sites, they have they own routing, and work properly, both locally and on the proxy-ed domains (example.com & example2.com).
localhost:8998: is a golang api, it works locally and also if I access example.com:8998 or example2.com:8998.
Is there something wrong with the conf?
EDIT: added more info to the question.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:9000/;
}
location /some/directory {
proxy_pass http://localhost:8998/;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://localhost:8999/;
}
}
Try this, adding the last / in the proxy_pass's should work.
I have recently started learning NGINX and encountered some problems. I am still getting and error 500, even if I have configured NGINX (1.4.6) with an error_page directive. The config works ( I get the woops.html as expected ) if I try not to send error 500 from the second upstream server. Here's my configuration file:
server {
listen 80 default_server;
root /srv/www;
index index.html index.htm;
server_name test.dev;
location / {
proxy_pass http://localhost:8080;
proxy_intercept_errors on;
error_page 500 #retry;
}
location #retry {
proxy_pass http://localhost:8081;
proxy_intercept_errors on;
error_page 500 /woops.html;
}
location = /woops.html {
root /srv/www;
}
}
server {
listen 8080;
listen localhost:8080;
server_name localhost;
root /srv/www;
location / {
return 500;
}
}
server {
listen 8081;
listen localhost:8081;
server_name localhost;
root /srv/www/app;
location / {
return 500;
}
}