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>;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Cấu hình với ProxyPass
server {
listen <PORT>;
listen [::]:<PORT>;
server_name <SERVER_NAME_OR_IP>;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass <FORWARD_URL>;
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 <PORT>;
listen [::]:<PORT>;
server_name <SERVER_NAME_OR_IP>;
root <PATH_TO_WEB_FOLDER>;
index index.php index.htm index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:<PATH_TO_PHP_FPM_SOCK_FILE>;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}