{"id":227,"date":"2016-03-30T22:48:37","date_gmt":"2016-03-30T21:48:37","guid":{"rendered":"https:\/\/solidt.eu\/blog\/?p=227"},"modified":"2025-09-02T20:05:46","modified_gmt":"2025-09-02T19:05:46","slug":"nginx-configuration-examples","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/nginx-configuration-examples\/","title":{"rendered":"Nginx configuration examples"},"content":{"rendered":"<p>Redirect all to https:<\/p>\n<pre lang=\"nginx\">server {\n\tlisten 80;\n\tserver_name myserver.com;\n\treturn 301 https:\/\/$server_name$request_uri;\n}\n<\/pre>\n<p>Nginx SSL configuration:<\/p>\n<pre lang=\"nginx\">server {\n\tlisten       443 ssl;\n\tserver_name  myserver.com;\n\n\tssl_certificate      \/etc\/ssl_keys\/fullchain.pem;\n\tssl_certificate_key  \/etc\/ssl_keys\/privkey.pem;\n\tssl_session_cache    shared:SSL:1m;\n\tssl_session_timeout  5m;\n\tssl_ciphers  HIGH:!aNULL:!MD5;\n\tssl_prefer_server_ciphers  on;\n}\n<\/pre>\n<p>Nginx PHP in subdirectory configuration:<\/p>\n<pre lang=\"nginx\">            location \/site {\n            index index.php;\n            location ~ \\.php(?:$|\/) {\n                include fastcgi_params;\n                fastcgi_pass 127.0.0.1:9000;\n                fastcgi_param SCRIPT_FILENAME $request_filename; # this should not be needed but it is?!\n            }\n            try_files $uri $uri\/ \/site\/index.php?$args;\n        }\n<\/pre>\n<pre lang=\"nginx\">server {\n    index  index.html index.htm index.php;\n\n    # just for allowing symlinks\n    disable_symlinks off;\n\n    # set a higher limit for allowing to upload large files\n    client_max_body_size 50m;\n\n\n# a nested location block with php hosted in a separate root\n    location \/agendav {\n        index  index.html index.htm index.php;\n#        root \/usr\/share\/webapps\/agendav\/web\/public;\n        alias \/usr\/share\/webapps\/agendav\/web\/public;\n\n        location ~ \/agendav(.*\\.php)(?:$|\/) {\n            include fastcgi_params;\n            set $fastcgi_script_name_ $document_root$1;\n            set $fastcgi_path_info_ $2;\n            fastcgi_param SCRIPT_FILENAME $fastcgi_script_name_;\n            fastcgi_param PATH_INFO $fastcgi_path_info_;\n#           add_header \"Content-Type\" \"text\/plain\";\n#           return 200 \"$fastcgi_script_name_\";\n            fastcgi_pass 127.0.0.1:9000;\n            fastcgi_intercept_errors on;\n        }\n    }\n\n\n\n    location ~ \\.php(?:$|\/) {\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n        include fastcgi_params;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        fastcgi_param PATH_INFO $fastcgi_path_info;\n        fastcgi_param HTTPS on;\n            #add_header \"Content-Type\" \"text\/plain\";\n            #return 200 $document_root$fastcgi_script_name;\n        fastcgi_pass 127.0.0.1:9000;\n        fastcgi_intercept_errors on;\n    }\n}\n<\/pre>\n<p>Nginx Web Socket proxy_pass on subfolder:<\/p>\n<pre lang=\"nginx\">server {\n\tlocation \/test {\n\n\t#remove the starting \/test\n\trewrite \/test\/(.*) \/$1  break;\n\n\t# this 3 lines below allow for Web Socket connections!\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\n        proxy_http_version 1.1;\n\n        proxy_redirect     off;\n        proxy_set_header   Host $host;\n\n        proxy_pass http:\/\/localhost:3001\/;\n    }\n}\n<\/pre>\n<p>Nginx debugging configuration or displaying variables:<\/p>\n<pre lang=\"nginx\">server {\n\tlocation ~ \\.php$ {\n\t\tinclude fastcgi.conf;\n\t\t\t\n\t\tadd_header Content-Type text\/plain;\n\t\treturn 200 $document_root$fastcgi_script_name;\n\t}\n}\n<\/pre>\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"sh\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">server {\n    server_name domain.tld www.domain.tld;\n    root \/var\/www\/wallabag\/web;\n\n    location \/ {\n        # try to serve file directly, fallback to app.php\n        try_files $uri \/app.php$is_args$args;\n    }\n    location ~ ^\/app\\.php(\/|$) {\n        # if, for some reason, you are still using PHP 5,\n        # then replace \/run\/php\/php7.0 by \/var\/run\/php5\n        fastcgi_pass unix:\/run\/php\/php7.0-fpm.sock;\n        fastcgi_split_path_info ^(.+\\.php)(\/.*)$;\n        include fastcgi_params;\n        # When you are using symlinks to link the document root to the\n        # current version of your application, you should pass the real\n        # application path instead of the path to the symlink to PHP\n        # FPM.\n        # Otherwise, PHP's OPcache may not properly detect changes to\n        # your PHP files (see https:\/\/github.com\/zendtech\/ZendOptimizerPlus\/issues\/126\n        # for more information).\n        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;\n        fastcgi_param DOCUMENT_ROOT $realpath_root;\n        # Prevents URIs that include the front controller. This will 404:\n        # http:\/\/domain.tld\/app.php\/some-path\n        # Remove the internal directive to allow URIs like this\n        internal;\n    }\n\n    # return 404 for all other php files not matching the front controller\n    # this prevents access to other php files you don't want to be accessible.\n    location ~ \\.php$ {\n        return 404;\n    }\n\n    error_log \/var\/log\/nginx\/wallabag_error.log;\n    access_log \/var\/log\/nginx\/wallabag_access.log;\n}<\/pre><\/div>\n\n\n\n<p>Use of variables<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"sh\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">server {\n    listen 80;\n    server_name auth.*;\n\n    return 301 https:\/\/$server_name$request_uri;\n}\n\nserver {\n    listen 443 ssl http2;\n    server_name auth.*;\n\n    include \/config\/nginx\/snippets\/ssl.conf;\n\n    set $upstream http:\/\/authelia:9091;\n\n    location \/ {\n        include \/config\/nginx\/snippets\/proxy.conf;\n        proxy_pass $upstream;\n    }\n\n    location = \/api\/verify {\n        proxy_pass $upstream;\n    }\n\n    location \/api\/authz\/ {\n        proxy_pass $upstream;\n    }\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Redirect all to https: server { listen 80; server_name myserver.com; return 301 https:\/\/$server_name$request_uri; } Nginx SSL configuration: server { listen 443 ssl; server_name myserver.com; ssl_certificate \/etc\/ssl_keys\/fullchain.pem; ssl_certificate_key \/etc\/ssl_keys\/privkey.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; } Nginx PHP in subdirectory configuration: location \/site { index index.php; location ~ \\.php(?:$|\/) { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-other-scripts"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=227"}],"version-history":[{"count":10,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/227\/revisions"}],"predecessor-version":[{"id":9737,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/227\/revisions\/9737"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}