Nginx

5. maaliskuuta 2021 | 218 näyttökertaa

#user html;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        /run/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    server_names_hash_bucket_size 64;

    #gzip  on;

    client_max_body_size 1024G;

    upstream php-handler {
    	server unix:/run/php-fpm/php-fpm.sock;
    }

    server {
	server_name test.example.com;

	location / {
	    proxy_pass http://localhost:8080;
	}
    }
    #server {
#	listen 80 default_server;
#	listen [::]:80 default_server;
#	server_name _;
#	return 301 https://$host$request_uri;
#    }


    server {
	server_name git.example.com;

	location / {
	    proxy_pass http://localhost:3009;
	}
    	
	listen 443 ssl; # managed by Certbot
    	ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem; # managed by Certbot
    	ssl_certificate_key /etc/letsencrypt/live/git.example.com/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 searx.example.com;

	location / {
	    proxy_pass http://localhost:8888;
	}
    	
	listen 443 ssl; # managed by Certbot
    	ssl_certificate /etc/letsencrypt/live/searx.example.com/fullchain.pem; # managed by Certbot
    	ssl_certificate_key /etc/letsencrypt/live/searx.example.com/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  nextdev.example.com;

	listen 80;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

	root /home/nextdev/nextcloud/;
       
	rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    	rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
    	
	location = /.well-known/carddav {
      		return 301 $scheme://$host:$server_port/remote.php/dav;
    	}

    	location = /.well-known/caldav {
      		return 301 $scheme://$host:$server_port/remote.php/dav;
    	}

	location / {
		rewrite ^ /index.php;
	}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
#        error_page   500 502 503 504  /50x.html;
#        location = /50x.html {
#            root   /usr/share/nginx/html;
#        }

location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
        deny all;
    }
    location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

	location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
        	fastcgi_split_path_info ^(.+\.php)(/.*)$;
        	try_files $fastcgi_script_name =404;
        	include fastcgi_params;
        	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        	fastcgi_param PATH_INFO $fastcgi_path_info;
        	fastcgi_param HTTPS on;
        	#Avoid sending the security headers twice
        	fastcgi_param modHeadersAvailable true;
        	fastcgi_param front_controller_active true;
		fastcgi_connect_timeout 60;
        	fastcgi_send_timeout 18000;
        	fastcgi_read_timeout 18000;
        	fastcgi_pass php-handler;
        	fastcgi_intercept_errors on;
        	fastcgi_request_buffering off;
    	}

location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463";
        # Add headers to serve security related headers (It is intended to
        # have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into
        # this topic first.
        #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
        #
        # WARNING: Only add the preload option once you read about
        # the consequences in https://hstspreload.org/. This option
        # will add the domain to a hardcoded list that is shipped
        # in all major browsers and getting removed from this list
        # could take several months.
        add_header Referrer-Policy "no-referrer" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header X-Download-Options "noopen" always;
        add_header X-Permitted-Cross-Domain-Policies "none" always;
        add_header X-Robots-Tag "none" always;
        add_header X-XSS-Protection "1; mode=block" always;

        # Optional: Don't log access to assets
        access_log off;
    }

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
        try_files $uri /index.php$request_uri;
        # Optional: Don't log access to other assets
        access_log off;
    }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    

}


    server {
        server_name  example.com;
	
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

	root /usr/share/webapps/nextcloud/;
       
	rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    	rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
    	
	location = /.well-known/carddav {
      		return 301 $scheme://$host:$server_port/remote.php/dav;
    	}

    	location = /.well-known/caldav {
      		return 301 $scheme://$host:$server_port/remote.php/dav;
    	}

	location /urandom {
	    root /usr/share/www;
	}

	location / {
		rewrite ^ /index.php;
	}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
#        error_page   500 502 503 504  /50x.html;
#        location = /50x.html {
#            root   /usr/share/nginx/html;
#        }

location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
        deny all;
    }
    location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

	location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
        	fastcgi_split_path_info ^(.+\.php)(/.*)$;
        	try_files $fastcgi_script_name =404;
        	include fastcgi_params;
        	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        	fastcgi_param PATH_INFO $fastcgi_path_info;
        	fastcgi_param HTTPS on;
        	#Avoid sending the security headers twice
        	fastcgi_param modHeadersAvailable true;
        	fastcgi_param front_controller_active true;
		fastcgi_connect_timeout 60;
        	fastcgi_send_timeout 18000;
        	fastcgi_read_timeout 18000;
        	fastcgi_pass php-handler;
        	fastcgi_intercept_errors on;
        	fastcgi_request_buffering off;
    	}

location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463";
        # Add headers to serve security related headers (It is intended to
        # have those duplicated to the ones above)
        # Before enabling Strict-Transport-Security headers please read into
        # this topic first.
        #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
        #
        # WARNING: Only add the preload option once you read about
        # the consequences in https://hstspreload.org/. This option
        # will add the domain to a hardcoded list that is shipped
        # in all major browsers and getting removed from this list
        # could take several months.
        add_header Referrer-Policy "no-referrer" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header X-Download-Options "noopen" always;
        add_header X-Permitted-Cross-Domain-Policies "none" always;
        add_header X-Robots-Tag "none" always;
        add_header X-XSS-Protection "1; mode=block" always;

        # Optional: Don't log access to assets
        access_log off;
    }

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
        try_files $uri /index.php$request_uri;
        # Optional: Don't log access to other assets
        access_log off;
    }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/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 {
	listen 80 default_server;
	server_name _;

	return 301 https://$host$request_uri;
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    
    #server {
       # listen       22438 ssl;
      #  server_name  localhost;

     #   ssl_certificate      cert.pem;
     #   ssl_certificate_key  cert.key;

     #   ssl_session_cache    shared:SSL:1m;
     #   ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
	
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}