basic configuration for an Nginx server - server block

This configuration is known as a “server block” in Nginx. Each block location handles different URL patterns and redirection for specific scripts or manipulations. Make any necessary adjustments to meet your site's specific needs.

 

Open the Nginx configuration file (usually located at /etc/nginx/nginx.conf) and including the server blocks as given below.

 

Don't forget to change "your_domain.com" to your domain name and root "/path/to/your/site"

Restart Nginx to apply the changes.

 

server {

    listen 80;

    server_name seu_dominio.com;

 

    root /caminho/para/o/seu/site;

    index index.php;

 

    location / {

        try_files $uri $uri/ /index.php?$args;

    }


 

    location /share-link {

        rewrite ^/share-link$ /submit.php last;

    }
 

    location /submit {

        rewrite ^/submit$ /submit.php last;

    }

 

    location ~ ^/category/([0-9]+)/(.*)/(.*) {

        rewrite ^/category/([0-9]+)/(.*)/(.*) /category.php?id=$1&name=$2&platform=$3 last;

    }


 

    location ~ ^/group/([0-9]+)/(.*) {

        rewrite ^/group/([0-9]+)/(.*) /link.php?id=$1&name=$2 last;

    }
 

    location ~ ^/link/([0-9]+)/(.*) {

        rewrite ^/link/([0-9]+)/(.*) /link2.php?id=$1&name=$2 last;

    }

 

    location ~ ^/pay/(.*)/([0-9]+)/(.*) {

        rewrite ^/pay/(.*)/([0-9]+)/(.*) /pay.php?code=$1&id=$2&name=$3 last;

    }
 

    location ~ ^/page/([0-9]+)/(.*) {

        rewrite ^/page/([0-9]+)/(.*) /page.php?id=$1&name=$2 last;

    }


 

    location ~ ^/confirm_email/([0-9]+) {

        rewrite ^/confirm_email/([0-9]+) /email_confirm.php?code=$1 last;

    }
 

    location ~ ^/confirm_account/([0-9]+) {

        rewrite ^/confirm_account/([0-9]+) /account_confirm.php?code=$1 last;

    }

 

    location ~ ^/edit-group/([0-9]+) {

        rewrite ^/edit-group/([0-9]+) /edit-group.php?id=$1 last;

    }

 

    location ~ ^/post/([0-9]+)/(.*) {

        rewrite ^/post/([0-9]+)/(.*) /blog.php?id=$1&name=$2 last;

    }

 

    error_page 404 /404.php;

}


 


 


 

an example of what it would look like on the server using "Cloud Panel":

 

server {

  listen 80;

  listen [::]:80;

  listen 443 ssl http2;

  listen [::]:443 ssl http2;

  {{ssl_certificate_key}}

  {{ssl_certificate}}

  server_name www.website.online;

  return 301 https://website.online$request_uri;

}

 

server {

  listen 80;

  listen [::]:80;

  listen 443 ssl http2;

  listen [::]:443 ssl http2;

  {{ssl_certificate_key}}

  {{ssl_certificate}}

  server_name website.com  www.website.com;

  {{root}}

 

  {{nginx_access_log}}

  {{nginx_error_log}}

 

  if ($scheme != "https") {

    rewrite ^ https://$host$uri permanent;

  }

 

  location ~ /.well-known {

    auth_basic off;

    allow all;

  }

 

  {{settings}}

 

  location / {

    {{varnish_proxy_pass}}

    proxy_set_header Host $http_host;

    proxy_set_header X-Forwarded-Host $http_host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_hide_header X-Varnish;

    proxy_redirect off;

    proxy_max_temp_file_size 0;

    proxy_connect_timeout      720;

    proxy_send_timeout         720;

    proxy_read_timeout         720;

    proxy_buffer_size          128k;

    proxy_buffers              4 256k;

    proxy_busy_buffers_size    256k;

    proxy_temp_file_write_size 256k;

  }

 

  location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf|map)$ {

    add_header Access-Control-Allow-Origin "*";

    expires max;

    access_log off;

  }

 

  if (-f $request_filename) {

    break;

  }

}

 

server {

  listen 8080;

  listen [::]:8080;

  server_name website.com www.website.com;

  {{root}}

 

  try_files $uri $uri/ /index.php?$args;

  index index.php index.html;

  

   location / {

 

        try_files $uri $uri/ /index.php?$args;

 

    }

    

    location /share-link {

 

        rewrite ^/share-link$ /submit.php last;

 

    }

 

 

 

    location /submit {

 

        rewrite ^/submit$ /submit.php last;

 

    }

 

 

 

    location ~ ^/category/([0-9]+)/(.*)/(.*) {

 

        rewrite ^/category/([0-9]+)/(.*)/(.*) /category.php?id=$1&name=$2&platform=$3 last;

 

    }

 

 

 

    location ~ ^/group/([0-9]+)/(.*) {

 

        rewrite ^/group/([0-9]+)/(.*) /link.php?id=$1&name=$2 last;

 

    }

 

 

 

    location ~ ^/link/([0-9]+)/(.*) {

 

        rewrite ^/link/([0-9]+)/(.*) /link2.php?id=$1&name=$2 last;

 

    }

 

 

 

    location ~ ^/pay/(.*)/([0-9]+)/(.*) {

 

        rewrite ^/pay/(.*)/([0-9]+)/(.*) /pay.php?code=$1&id=$2&name=$3 last;

 

    }

 

 

 

    location ~ ^/page/([0-9]+)/(.*) {

 

        rewrite ^/page/([0-9]+)/(.*) /page.php?id=$1&name=$2 last;

 

    }

 

 

 

    location ~ ^/confirm_email/([0-9]+) {

 

        rewrite ^/confirm_email/([0-9]+) /email_confirm.php?code=$1 last;

 

    }

 

 

 

    location ~ ^/confirm_account/([0-9]+) {

 

        rewrite ^/confirm_account/([0-9]+) /account_confirm.php?code=$1 last;

 

    }

 

 

 

    location ~ ^/edit-group/([0-9]+) {

 

        rewrite ^/edit-group/([0-9]+) /edit-group.php?id=$1 last;

 

    }

 

 

 

    location ~ ^/post/([0-9]+)/(.*) {

 

        rewrite ^/post/([0-9]+)/(.*) /blog.php?id=$1&name=$2 last;

 

    }

 

 

 

    error_page 404 /404.php;

  location ~ \.php$ 

 

///outras configurações

 

  if (-f $request_filename) {

    break;

  }

}


 


Usamos cookies para melhorar sua experiência de navegação, veicular anúncios ou conteúdo personalizado e analisar nosso tráfego. Ao clicar em “Aceitar”, você concorda com o uso de cookies. saiba mais

Permitir