Một số cấu hình Nginx thông dụng

1 min read

Cấu hình cho web HTML tĩnh

server {
    listen ;
    listen [::]:; 
    server_name ;
    
    root ;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
 }

Cấu hình với ProxyPass

server {
    listen ;
    listen [::]:;
    server_name ;

    location / {
       proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
       proxy_set_header host $host;
       proxy_pass ;
       proxy_http_version 1.1;
       proxy_set_header upgrade $http_upgrade;
       proxy_set_header connection "upgrade";
       proxy_cache_bypass $http_upgrade;
    }
  }

Cấu hình cho PHP/Laravel

server {
    listen ;
    listen [::]:;
    server_name ;

    root ;

    index index.php index.htm index.html;

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

    location ~ \.php$ {
        fastcgi_pass unix:;
        fastcgi_index index.php;
        fastcgi_param script_filename $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
 }

Bận cà phê, bận chơi.

Bạn có thể thích những bài đăng này

  • Bước 1: Truy cập trang https://dev.mysql.com/downloads/repo/yum/ trên trình duyệt. Trang web sẽ hiển thị các phiên bản và định danh của các phiên bản đó. Bước 2: Trê…
  • Bước 1: Cấu hình bản ghi trên Google DomainsTruy cập Google Domains, chọn domain cần cấu hình, hoặc mua domain mới nếu chưa có.Tại thanh menu bên phải, chọn vào mục DNSTìm đến mục&…
  • Cấu hình cho web HTML tĩnh server { listen <PORT>; listen [::]:<PORT>; server_name <SERVER_NAME_OR_IP>; root <PATH_TO_WEB_FOLDER>; …
  • Cách 1: Cài Nodejs qua NodeSource repository1. Tải và cài đặt NodeSource repository:Với phiên bản 10xcurl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -Với phiên bản …
  • Bước 1: Sửa file cấu hình MySQLTrên terminal gõ lệnh:sudo nano /etc/my.cnfThêm dòng lệnh sau:bind-address = 0.0.0.0Lưu và đóng file cấu hình lại, sau đó khởi động lại MySQL service…
  • Cài đặt Redis Để cài đặt redis trên CentOS, ta gõ lệnh: sudo yum install redis Khởi động redis service và kiểm tra trạng thái Để khởi động redis service, gõ lệnh: sudo s…

Đăng nhận xét