Skip to content

Instantly share code, notes, and snippets.

@nhatphamcdn
Forked from cbmd/default.conf
Created February 3, 2021 06:20
Show Gist options
  • Save nhatphamcdn/e1cd31a615de3b03c03bca07f1d76ab8 to your computer and use it in GitHub Desktop.
Save nhatphamcdn/e1cd31a615de3b03c03bca07f1d76ab8 to your computer and use it in GitHub Desktop.

Revisions

  1. @MetalGuardian MetalGuardian revised this gist Nov 4, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion default.conf
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,9 @@ server {
    }

    # allow php only in root index.php
    location ~ "^/index\.php$" {
    #location ~ "^/index\.php$" {
    # allow execute all php files
    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

  2. @MetalGuardian MetalGuardian revised this gist Nov 4, 2012. 2 changed files with 44 additions and 55 deletions.
    47 changes: 44 additions & 3 deletions default.conf
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,14 @@ server {

    set $domain $host;

    # check one name domain for simple application
    if ($domain ~ "^(.[^.]*)\.dev$") {
    set $domain $1;
    set $rootpath "${domain}";
    set $servername "${domain}.dev";
    }

    # check multi name domain to multi application
    if ($domain ~ "^(.*)\.(.[^.]*)\.dev$") {
    set $subdomain $1;
    set $domain $2;
    @@ -19,13 +21,18 @@ server {

    server_name $servername;

    access_log "/var/log/nginx/server.${servername}.access.log";
    error_log "/var/log/nginx/server.dev.error.log";

    root $basepath/$rootpath;

    # check file exist and send request sting to index.php
    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
    # allow php only in root index.php
    location ~ "^/index\.php$" {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    @@ -34,11 +41,45 @@ server {
    include fastcgi_params;
    }

    # configure phpmyadmin path
    location /phpmyadmin {
    root /usr/share/;
    index index.php;
    location ~ ^/phpmyadmin/(.+\.php)$ {
    try_files $uri =404;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 4k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }

    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    }

    # disallow access to apache configs
    location ~ /\.ht {
    deny all;
    }


    # disallow access to git configs path
    location ~ /\.git {
    deny all;
    }
    }

    # disallow access to yii code path
    location ~ /(protected|themes/classic/views)/ {
    deny all;
    }
    }
    52 changes: 0 additions & 52 deletions main.conf
    Original file line number Diff line number Diff line change
    @@ -1,52 +0,0 @@
    server {
    root /var/www;
    index index.php;

    location / {
    try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }


    location ~ /\.ht {
    deny all;
    }

    location ~ /\.git {
    deny all;
    }

    location /phpmyadmin {
    root /usr/share/;
    index index.php;
    location ~ ^/phpmyadmin/(.+\.php)$ {
    try_files $uri =404;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 4k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }

    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    }
    }
  3. @MetalGuardian MetalGuardian revised this gist Nov 4, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions dnsmasq
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # sudo apt-get install dnsmasq
    # echo "address=/.dev/127.0.0.1" >> /etc/dnsmasq.conf
  4. @MetalGuardian MetalGuardian revised this gist Nov 4, 2012. 1 changed file with 52 additions and 0 deletions.
    52 changes: 52 additions & 0 deletions main.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    server {
    root /var/www;
    index index.php;

    location / {
    try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }


    location ~ /\.ht {
    deny all;
    }

    location ~ /\.git {
    deny all;
    }

    location /phpmyadmin {
    root /usr/share/;
    index index.php;
    location ~ ^/phpmyadmin/(.+\.php)$ {
    try_files $uri =404;
    root /usr/share/;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 4k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }

    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    }
    }
  5. @MetalGuardian MetalGuardian renamed this gist Nov 4, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @MetalGuardian MetalGuardian revised this gist Nov 4, 2012. 1 changed file with 44 additions and 1 deletion.
    45 changes: 44 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1 +1,44 @@
    server{}
    server {
    index index.php;
    set $basepath "/var/www";

    set $domain $host;

    if ($domain ~ "^(.[^.]*)\.dev$") {
    set $domain $1;
    set $rootpath "${domain}";
    set $servername "${domain}.dev";
    }

    if ($domain ~ "^(.*)\.(.[^.]*)\.dev$") {
    set $subdomain $1;
    set $domain $2;
    set $rootpath "${domain}/${subdomain}/www/";
    set $servername "${subdomain}.${domain}.dev";
    }

    server_name $servername;

    root $basepath/$rootpath;

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

    location ~ /\.ht {
    deny all;
    }

    location ~ /\.git {
    deny all;
    }
    }
  7. @MetalGuardian MetalGuardian created this gist Nov 4, 2012.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    server{}