環境 : Ubuntu20.04 | php7.4 | Nginx
第一步 : 伺服器已安裝好nginx 和網站所需軟件
第二步 : 開啟 nginx 設定檔
- 以下為nginx 設定檔內容
- Linux 設定檔通常在 /etc/nginx/sites-available/default
- Windows 設定檔通常在nginx資料夾下,會有一個 /nginx/conf/nginx.conf
- Mac m1/Mac m2 設定檔通常在 /opt/homebrew/etc/nginx/nginx.conf
- 將專案與該網域做綁定
server {
listen 80;
root /var/www/project1;
index index.php;
client_max_body_size 16M;
server_name project1.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
root /var/www/project2;
index index.php;
client_max_body_size 16M;
server_name project2.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
第三步 : 重新載入nginx
sudo service nginx reload
sudo nginx -t
- 若沒有輸出error 則表示正常運作了
搶先發佈留言