server {
    server_name orgmode.org;
    root /home/build/orgmode/;
    index index.html;
    location / {
	try_files $uri $uri/ =404;
    }

    location /worg/images/ {
        autoindex on;
    }

    error_page 404 /errors/404.html;
    error_page 403 /errors/403.html;
    error_page 400 /errors/400.html;
    error_page 500 /errors/500.html;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/orgmode.org-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/orgmode.org-0001/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    rewrite ^/list(.*) https://list.orgmode.org$1 permanent;
    rewrite ^/worg/dev/org-syntax\.html https://orgmode.org/worg/org-syntax.html permanent;
    rewrite ^/contribute\.html https://orgmode.org/worg/org-contribute.html permanent;

    location /manual {

        rewrite /Add_002don-packages\.html Add_002don-Packages.html permanent;
        rewrite /Adding-export-back_002dends\.html Adding-Export-Back_002dends.html permanent;
        rewrite /Adding-hyperlink-Types\.html Adding-Hyperlink-Types.html permanent;
        rewrite /Advanced-export-configuration\.html Advanced-Export-Configuration.html permanent;
        rewrite /Agenda-column-View\.html Agenda-Column-View.html permanent;
        rewrite /Agenda-commands\.html Agenda-Commands.html permanent;
        rewrite /Agenda-dispatcher\.html Agenda-Dispatcher.html permanent;
        rewrite /Agenda-files\.html Agenda-Files.html permanent;
        rewrite /Agenda-views\.html Agenda-Views.html permanent;
        rewrite /Batch-execution\.html Batch-Execution.html permanent;
        rewrite /Beamer-export\.html Beamer-Export.html permanent;
        rewrite /Breaking-down-Tasks\.html Breaking-Down-Tasks.html permanent;
        rewrite /Built_002din-agenda-Views\.html Built_002din-Agenda-Views.html permanent;
        rewrite /Built_002din-table-Editor\.html Built_002din-Table-Editor.html permanent;
        rewrite /Clean-view\.html Clean-View.html permanent;
        rewrite /Clocking-work-Time\.html Clocking-Work-Time.html permanent;
        rewrite /Code-evaluation-Security\.html Code-Evaluation-Security.html permanent;
        rewrite /Column-groups\.html Column-Groups.html permanent;
        rewrite /Column-view\.html Column-View.html permanent;
        rewrite /Column-width-and-alignment\.html Column-Width-and-Alignment.html permanent;
        rewrite /Comment-lines\.html Comment-Lines.html permanent;
        rewrite /Creating-footnotes\.html Creating-Footnotes.html permanent;
        rewrite /Creating-timestamps\.html Creating-Timestamps.html permanent;
        rewrite /Custom-agenda-Views\.html Custom-Agenda-Views.html permanent;
        rewrite /Custom-searches\.html Custom-Searches.html permanent;
        rewrite /Dates-and-times\.html Dates-and-Times.html permanent;
        rewrite /Deadlines-and-scheduling\.html Deadlines-and-Scheduling.html permanent;
        rewrite /Document-structure\.html Document-Structure.html permanent;
        rewrite /Dynamic-blocks\.html Dynamic-Blocks.html permanent;
        rewrite /Editing-source-Code\.html Editing-Source-Code.html permanent;
        rewrite /Effort-estimates\.html Effort-Estimates.html permanent;
        rewrite /Emphasis-and-monospace\.html Emphasis-and-Monospace.html permanent;
        rewrite /Evaluating-code-Blocks\.html Evaluating-Code-Blocks.html permanent;
        rewrite /Export-in-foreign-buffers\.html Export-in-Foreign-Buffers.html permanent;
        rewrite /Export-settings\.html Export-Settings.html permanent;
        rewrite /Exporting-agenda-Views\.html Exporting-Agenda-Views.html permanent;
        rewrite /Exporting-code-Blocks\.html Exporting-Code-Blocks.html permanent;
        rewrite /External-links\.html External-Links.html permanent;
        rewrite /Extracting-agenda-information\.html Extracting-Agenda-Information.html permanent;
        rewrite /Extracting-source-Code\.html Extracting-Source-Code.html permanent;
        rewrite /Frames-and-blocks-in-beamer\.html Frames-and-Blocks-in-Beamer.html permanent;
        rewrite /HTML-export\.html HTML-Export.html permanent;
        rewrite /Handling-links\.html Handling-Links.html permanent;
        rewrite /History-and-acknowledgments\.html History-and-Acknowledgments.html permanent;
        rewrite /Horizontal-rules\.html Horizontal-Rules.html permanent;
        rewrite /In_002dbuffer-settings\.html In_002dbuffer-Settings.html permanent;
        rewrite /Include-files\.html Include-Files.html permanent;
        rewrite /Internal-links\.html Internal-Links.html permanent;
        rewrite /Key-bindings-and-useful-functions\.html Key-bindings-and-Useful-Functions.html permanent;
        rewrite /LaTeX-export\.html LaTeX-Export.html permanent;
        rewrite /LaTeX_002fpdf-export-commands\.html LaTeX_002fPDF-export-commands.html permanent;
        rewrite /Link-abbreviations\.html Link-Abbreviations.html permanent;
        rewrite /Link-format\.html Link-Format.html permanent;
        rewrite /Literal-examples\.html Literal-Examples.html permanent;
        rewrite /Macro-replacement\.html Macro-Replacement.html permanent;
        rewrite /Markdown-export\.html Markdown-Export.html permanent;
        rewrite /Markup-for-rich-contents\.html Markup-for-Rich-Contents.html permanent;
        rewrite /MathML-and-opendocument-formula-files\.html MathML-and-OpenDocument-formula-files.html permanent;
        rewrite /Noweb-reference-Syntax\.html Noweb-Reference-Syntax.html permanent;
        rewrite /OpenDocument-text-Export\.html OpenDocument-Text-Export.html permanent;
        rewrite /Org-crypt\.html Org-Crypt.html permanent;
        rewrite /Org-export\.html Org-Export.html permanent;
        rewrite /Org-mobile\.html Org-Mobile.html permanent;
        rewrite /Org-plot\.html Org-Plot.html permanent;
        rewrite /Org-syntax\.html Org-Syntax.html permanent;
        rewrite /Orgtbl-mode\.html Orgtbl-Mode.html permanent;
        rewrite /Other-built_002din-back_002dends\.html Other-Built_002din-Back_002dends.html permanent;
        rewrite /Plain-lists\.html Plain-Lists.html permanent;
        rewrite /Presentation-and-sorting\.html Presentation-and-Sorting.html permanent;
        rewrite /Progress-logging\.html Progress-Logging.html permanent;
        rewrite /Properties-and-columns\.html Properties-and-Columns.html permanent;
        rewrite /Property-inheritance\.html Property-Inheritance.html permanent;
        rewrite /Property-searches\.html Property-Searches.html permanent;
        rewrite /Property-syntax\.html Property-Syntax.html permanent;
        rewrite /RSS-feeds\.html RSS-Feeds.html permanent;
        rewrite /Radio-targets\.html Radio-Targets.html permanent;
        rewrite /Refile-and-copy\.html Refile-and-Copy.html permanent;
        rewrite /Refiling-and-archiving\.html Refiling-and-Archiving.html permanent;
        rewrite /Results-of-evaluation\.html Results-of-Evaluation.html permanent;
        rewrite /Sample-configuration\.html Sample-Configuration.html permanent;
        rewrite /Search-options\.html Search-Options.html permanent;
        rewrite /Setting-tags\.html Setting-Tags.html permanent;
        rewrite /Sparse-trees\.html Sparse-Trees.html permanent;
        rewrite /Special-agenda-Views\.html Special-Agenda-Views.html permanent;
        rewrite /Special-properties\.html Special-Properties.html permanent;
        rewrite /Special-symbols\.html Special-Symbols.html permanent;
        rewrite /Speed-keys\.html Speed-Keys.html permanent;
        rewrite /Speeding-up-Your-Agendas\.html Speeding-Up-Your-Agendas.html permanent;
        rewrite /Structure-editing\.html Structure-Editing.html permanent;
        rewrite /Structure-of-code-blocks\.html Structure-of-Code-Blocks.html permanent;
        rewrite /Subscripts-and-superscripts\.html Subscripts-and-Superscripts.html permanent;
        rewrite /TODO-basics\.html TODO-Basics.html permanent;
        rewrite /TODO-extensions\.html TODO-Extensions.html permanent;
        rewrite /TODO-items\.html TODO-Items.html permanent;
        rewrite /TTY-keys\.html TTY-Keys.html permanent;
        rewrite /Table-of-contents\.html Table-of-Contents.html permanent;
        rewrite /Tables-in-arbitrary-syntax\.html Tables-in-Arbitrary-Syntax.html permanent;
        rewrite /Tag-hierarchy\.html Tag-Hierarchy.html permanent;
        rewrite /Tag-inheritance\.html Tag-Inheritance.html permanent;
        rewrite /Tag-searches\.html Tag-Searches.html permanent;
        rewrite /Texinfo-export\.html Texinfo-Export.html permanent;
        rewrite /The-export-Dispatcher\.html The-Export-Dispatcher.html permanent;
        rewrite /The-spreadsheet\.html The-Spreadsheet.html permanent;
        rewrite /The-very-busy-c_002dc-c_002dc-key\.html The-Very-Busy-C_002dc-C_002dc-Key.html permanent;
        rewrite /Triggering-publication\.html Triggering-Publication.html permanent;
        rewrite /Uploading-files\.html Uploading-Files.html permanent;
        rewrite /Using-header-Arguments\.html Using-Header-Arguments.html permanent;
        rewrite /Using-links-Outside-Org\.html Using-Links-Outside-Org.html permanent;
        rewrite /Using-multiple-tblfm-lines\.html Using-multiple-TBLFM-lines.html permanent;
        rewrite /Using-the-mapping-api\.html Using-the-Mapping-API.html permanent;
        rewrite /Using-the-property-api\.html Using-the-Property-API.html permanent;
        rewrite /Visibility-cycling\.html Visibility-Cycling.html permanent;
        rewrite /Working-with-source-code\.html Working-with-Source-Code.html permanent;
        rewrite /iCalendar-export\.html iCalendar-Export.html permanent;
    }

    location /guide {

        rewrite /Agenda-commands\.html Agenda-Commands.html permanent;
        rewrite /Agenda-dispatcher\.html Agenda-Dispatcher.html permanent;
        rewrite /Agenda-files\.html Agenda-Files.html permanent;
        rewrite /Agenda-views\.html Agenda-Views.html permanent;
        rewrite /Breaking-down-Tasks\.html Breaking-Down-Tasks.html permanent;
        rewrite /Built_002din-agenda-Views\.html Built_002din-Agenda-Views.html permanent;
        rewrite /Capture-refile-Archive\.html Capture-Refile-Archive.html permanent;
        rewrite /Clocking-work-Time\.html Clocking-Work-Time.html permanent;
        rewrite /Comment-lines\.html Comment-Lines.html permanent;
        rewrite /Creating-footnotes\.html Creating-Footnotes.html permanent;
        rewrite /Creating-timestamps\.html Creating-Timestamps.html permanent;
        rewrite /Custom-agenda-Views\.html Custom-Agenda-Views.html permanent;
        rewrite /Dates-and-times\.html Dates-and-Times.html permanent;
        rewrite /Deadlines-and-scheduling\.html Deadlines-and-Scheduling.html permanent;
        rewrite /Document-structure\.html Document-Structure.html permanent;
        rewrite /Emphasis-and-monospace\.html Emphasis-and-Monospace.html permanent;
        rewrite /Export-settings\.html Export-Settings.html permanent;
        rewrite /External-links\.html External-Links.html permanent;
        rewrite /HTML-export\.html HTML-Export.html permanent;
        rewrite /Handling-links\.html Handling-Links.html permanent;
        rewrite /Include-files\.html Include-Files.html permanent;
        rewrite /LaTeX-export\.html LaTeX-Export.html permanent;
        rewrite /Multi_002dstate-workflow\.html Multi_002dstate-Workflow.html permanent;
        rewrite /Plain-lists\.html Plain-Lists.html permanent;
        rewrite /Progress-logging\.html Progress-Logging.html permanent;
        rewrite /Refile-and-copy\.html Refile-and-Copy.html permanent;
        rewrite /Sparse-trees\.html Sparse-Trees.html permanent;
        rewrite /Structure-editing\.html Structure-Editing.html permanent;
        rewrite /TODO-basics\.html TODO-Basics.html permanent;
        rewrite /TODO-items\.html TODO-Items.html permanent;
        rewrite /Table-of-contents\.html Table-of-Contents.html permanent;
        rewrite /The-export-dispatcher\.html The-Export-Dispatcher.html permanent;
        rewrite /Visibility-cycling\.html Visibility-Cycling.html permanent;
        rewrite /Working-with-source-code\.html Working-with-Source-Code.html permanent;
        rewrite /iCalendar-export\.html iCalendar-Export.html permanent;
        rewrite /ASCII_002fUTF_002d8-export\.html ASCII_002fUTF_002d8-Export.html permanent;
    }

}

server {
    server_name www.orgmode.org;
    return 301 https://orgmode.org;
    listen 443 ssl; # managed by Certbot
    # ssl_certificate /etc/letsencrypt/live/orgmode.org-0001/fullchain.pem; # managed by Certbot
    # ssl_certificate_key /etc/letsencrypt/live/orgmode.org-0001/privkey.pem; # managed by Certbot
    # include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/www.orgmode.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.orgmode.org/privkey.pem; # managed by Certbot
}

server {
    if ($host = code.orgmode.org) {
        return 301 https://$host$request_uri;
        } # managed by Certbot

        listen 80;
        server_name code.orgmode.org;
        return 404; # managed by Certbot
}

server {
    server_name code.orgmode.org;
    root /home/build/orgmode/;
    index index.html;
    location / {
	try_files $uri $uri/ =404;
    }

    rewrite ^/bzg/org-mode.git(.*) https://git.savannah.gnu.org/git/emacs/org-mode.git$1 permanent;
    rewrite ^/bzg/org-mode/commit/(.*) https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=$1 permanent;
    rewrite ^/bzg/org-mode https://git.savannah.gnu.org/cgit/emacs/org-mode.git/ permanent;
    rewrite ^/bzg/orgweb https://git.sr.ht/~bzg/orgweb permanent;
    rewrite ^/bzg/worg https://git.sr.ht/~bzg/worg permanent;
    rewrite ^ https://sr.ht/~bzg/org/sources permanent;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/code.orgmode.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/code.orgmode.org/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = www.orgmode.org) {
        return 301 https://orgmode.org;
        } # managed by Certbot

        if ($host = orgmode.org) {
            return 301 https://$host$request_uri;
            } # managed by Certbot

            listen 80;
            server_name orgmode.org www.orgmode.org;
            return 404; # managed by Certbot
}

server {
    if ($host = updates.orgmode.org) {
        return 301 https://$host$request_uri;
        } # managed by Certbot

        server_name updates.orgmode.org;
        listen 80;
        return 404; # managed by Certbot
}

server {
    server_name updates.orgmode.org;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    rewrite ^/feed/updates https://tracker.orgmode.org/index.rss permanent;
    rewrite ^/feed/bugs https://tracker.orgmode.org/bugs.rss permanent;
    rewrite ^/feed/patches https://tracker.orgmode.org/patches.rss permanent;
    rewrite ^/ https://tracker.orgmode.org permanent;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/updates.orgmode.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/updates.orgmode.org/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    server_name tracker.orgmode.org;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_hide_header       X-Frame-Options;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_pass http://localhost:3002;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/tracker.orgmode.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/tracker.orgmode.org/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = tracker.orgmode.org) {
        return 301 https://$host$request_uri;
        } # managed by Certbot

        server_name tracker.orgmode.org;
        listen 80;
        return 404; # managed by Certbot
}
