Skip to content

Instantly share code, notes, and snippets.

@vikbert
Last active March 29, 2018 15:10
Show Gist options
  • Select an option

  • Save vikbert/e6930f44e6ca205317c37c35818eec2e to your computer and use it in GitHub Desktop.

Select an option

Save vikbert/e6930f44e6ca205317c37c35818eec2e to your computer and use it in GitHub Desktop.
[nginx] nginx config and tips #nginx #web-server

caching static resources

    location ~*  ^.+\.(jpg|jpeg|png|gif|ico|svg|css|js)$ {
        expires max;
    }

basic authentication

	auth_basic "Restricted";
	auth_basic_user_file /etc/nginx/.htpasswd;

nginx ubup config sample


server {
    listen 80;
    server_name _;
    root /srv/www/shop/web/;

    location / {
        auth_basic  "secured ubup stage";
        auth_basic_user_file /etc/nginx/.htpasswd;
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/(app)\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_pass 127.0.0.1:9000;
        internal;
    }

    error_log /var/log/nginx/fpm_error.log;
    access_log /var/log/nginx/fpm_access.log;
}
server {
    listen       443;
    server_name _;
    root /srv/www/shop/web/;

    ssl     on;
    ssl_certificate /etc/nginx/ssl/www.stage.ub.local.crt;
    ssl_certificate_key     /etc/nginx/ssl/www.stage.ub.local.key;

    location / {
        auth_basic  "secured ubup stage";
        auth_basic_user_file /etc/nginx/.htpasswd;
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/(app)\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_pass 127.0.0.1:9000;
        internal;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment