Skip to main content
Version: 6.0 (Unstable) 🚧

HTTP Server

SRS Embeded a HTTP web server, supports api and simple HTTP file for HLS.

To deploy SRS HTTP server, read Usage: HTTP

The SRS Embeded HTTP server is rewrite refer to go http module, so it's ok to use srs as http server. Read #277

Remark: The SRS HTTP server is just a origin HTTP server, for HTTP edge server, please use NGINX, SQUID and ATS.

SRS also works well with HTTP reverse proxy servers, like NGINX and Caddy.

Use Scenario

The SRS Embeded HTTP server is design to provides basic HTTP service, like the camera of mobile phone.

SRS should provides HTTP api, which is actually a embeded HTTP server.

Actually, RTMP is more complex than HTTP, so HTTP server on st is absolutely ok. The HTTP Server in SRS1.0 is expirement, I will enhance it future.


Config the HTTP port and root.

# embeded http server in srs.
# the http streaming config, for HLS/HDS/DASH/HTTPProgressive
# global config for http streaming, user must config the http section for each vhost.
# the embed http server used to substitute nginx in ./objs/nginx,
# for example, srs runing in arm, can provides RTMP and HTTP service, only with srs installed.
# user can access the http server pages, generally:
#       curl
# which will show srs version and welcome to srs.
# @remeark, the http embeded stream need to config the vhost, for instance, the __defaultVhost__
# need to open the feature http of vhost.
http_server {
    # whether http streaming service is enabled.
    # default: off
    enabled         on;
    # the http streaming port
    # @remark, if use lower port, for instance 80, user must start srs by root.
    # default: 8080
    listen          8080;
    # the default dir for http root.
    # default: ./objs/nginx/html
    dir             ./objs/nginx/html;

And, each vhost can specifies the dir.

vhost your_vhost {
    # http static vhost specified config
    http_static {
        # whether enabled the http static service for vhost.
        # default: off
        enabled     on;
        # the url to mount to, 
        # typical mount to [vhost]/
        # the variables:
        #       [vhost] current vhost for http server.
        # @remark the [vhost] is optional, used to mount at specified vhost.
        # @remark the http of __defaultVhost__ will override the http_stream section.
        # for example:
        #       mount to [vhost]/
        #           access by
        #       mount to [vhost]/hls
        #           access by
        #       mount to /
        #           access by
        #           or by
        #       mount to /hls
        #           access by
        #           or by
        # default: [vhost]/
        mount       [vhost]/hls;
        # main dir of vhost,
        # to delivery HTTP stream of this vhost.
        # default: ./objs/nginx/html
        dir         ./objs/nginx/html/hls;

Remark: The http_stream of SRS1 renamed to http_server in SRS2, which specifies the global HTTP server config, used to delivery http static files, for dvr files(HLS/FLV/HDS/MPEG-DASH).

Remark: The http of vhost of SRS1 renamed to http_static, similar to global http_server for HTTP static files delivery. While the http_remux introduced in SRS2 is dynamic remux RTMP to HTTP Live FLV/Mp3/Aac/HLS/Hds/MPEG-DASH stream.

HTTPS Server

SRS supports HTTPS, just enable it in the configuration. By default, it uses a sub-signed certificate. If you need to use a CA-issued certificate, please replace the relevant files. The related configuration is as follows:

http_server {
    https {
        # Whether enable HTTPS Streaming.
        # Overwrite by env SRS_HTTP_SERVER_HTTPS_ENABLED
        # default: off
        enabled on;
        # The listen endpoint for HTTPS Streaming.
        # Overwrite by env SRS_HTTP_SERVER_HTTPS_LISTEN
        # default: 8088
        listen 8088;
        # The SSL private key file, generated by:
        #       openssl genrsa -out server.key 2048
        # Overwrite by env SRS_HTTP_SERVER_HTTPS_KEY
        # default: ./conf/server.key
        key ./conf/server.key;
        # The SSL public cert file, generated by:
        #       openssl req -new -x509 -key server.key -out server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/"
        # Overwrite by env SRS_HTTP_SERVER_HTTPS_CERT
        # default: ./conf/server.crt
        cert ./conf/server.crt;


SRS has CORS (Cross-Origin Resource Sharing) support enabled by default. The related configuration is as follows:

http_server {
    # whether enable crossdomain request.
    # for both http static and stream server and apply on all vhosts.
    # Overwrite by env SRS_HTTP_SERVER_CROSSDOMAIN
    # default: on
    crossdomain on;


Only some MIME is supported:

File ext nameContent-Type
.tsContent-Type: video/MP2T;charset=utf-8
.m3u8Content-Type: application/x-mpegURL;charset=utf-8
.jsonContent-Type: application/json;charset=utf-8
.cssContent-Type: text/css;charset=utf-8
.swfContent-Type: application/x-shockwave-flash;charset=utf-8
.jsContent-Type: text/javascript;charset=utf-8
.xmlContent-Type: text/xml;charset=utf-8
OthersContent-Type: text/html;charset=utf-8


Supported HTTP method:

  • GET: Query API, or download file.



  • /api/ SRS HTTP API
  • /rtc/ SRS WebRTC API


  • /{app}/{stream} HTTP Stream mounted by publisher.

The bellow is some reverse proxy to work with SRS.

Note: Generally, a proxy can be used to route API and Stream together based on the path.

Nginx Proxy

The config for NGINX as file nginx.conf:

worker_processes  1;
events {
    worker_connections  1024;

http {
    include             /etc/nginx/mime.types;

    server {
        listen       80;
        listen       443 ssl http2;
        server_name  _;
        ssl_certificate      /usr/local/srs/conf/server.crt;
        ssl_certificate_key  /usr/local/srs/conf/server.key;

        # For SRS homepage, console and players
        location ~ ^/(console|players)/ {
        # For SRS streaming, for example:
        location ~ ^/.+/.*\.(flv|m3u8|ts|aac|mp3)$ {
        # For SRS backend API for console.
        # For SRS WebRTC publish/play API.
        location ~ ^/(api|rtc)/ {

Caddy Proxy

The config for CaddyServer with automatic HTTPS, use the config file Caddyfile.

For HTTP server, note that to set the default port:

reverse_proxy /*
reverse_proxy /api/*
reverse_proxy /rtc/*

For HTTPS server, please enable a domain name: {
  reverse_proxy /*
  reverse_proxy /api/*
  reverse_proxy /rtc/*

Start the CaddyServer:

caddy start -config Caddyfile

Nodejs KOA Proxy

The nodejs koa proxy also works well for SRS, please use koa-proxies based by node-http-proxy, here is an example:

const Koa = require('koa');
const proxy = require('koa-proxies');
const BodyParser = require('koa-bodyparser');
const Router = require('koa-router');

const app = new Koa();
app.use(proxy('/api/', {target: ''}));
app.use(proxy('/rtc/', {target: ''}));
app.use(proxy('/*/*.(flv|m3u8|ts|aac|mp3)', {target: ''}));
app.use(proxy('/console/', {target: ''}));
app.use(proxy('/players/', {target: ''}));

// Start body-parser after proxies, see

// APIs that depends on body-parser
const router = new Router();
router.all('/', async (ctx) => {
  ctx.body = 'Hello World';

app.listen(3000, () => {
  console.log(`Server start on http://localhost:3000`);

Save it as index.js, then run:

npm init -y 
npm install koa koa-proxies koa-proxies koa-bodyparser koa-router
node .


Well httpx-static is a simple HTTP/HTTPS proxy written by Go:

go get
cd $GOPATH/bin
./httpx-static -http=80 -https=443 \
  -skey /usr/local/srs/etc/server.key -scert /usr/local/srs/etc/server.crt \
  -proxy= \
  -proxy= \

Please make sure the path / is the last one.

Winlin 2015.1