Back To Home

Name: Ngày 25: Cấu hình IIS cho Sitecore

🏗️ Ngày 25: Cấu hình IIS cho Sitecore (CM / CD / Identity Server)

Đây là một trong những phần quan trọng nhất khi triển khai Sitecore trên môi trường local, QA, UAT hoặc Production.


1️⃣ Kiến trúc IIS trong Sitecore

Một solution Sitecore thường có 3 site chạy trên IIS:

Vai trò Tên mặc định Mục đích
CM (Content Management) sc.dev.local Dành cho marketer, editor tạo content
CD (Content Delivery) sc.cd.dev.local Dành cho visitor truy cập website
Identity Server identityserver.dev.local Xác thực user (Sitecore Identity)

CMCD đều chạy code Sitecore nhưng cấu hình khác nhau.
Identity Server là một project riêng.


2️⃣ Tạo Website mới trong IIS

✔ Bước 1: Mở IIS Manager

Windows + R → inetmgr

✔ Bước 2: Add Website

  • Site name: sc.dev.local

  • Physical path: thư mục cài đặt Sitecore
    Ví dụ: C:\inetpub\wwwroot\sc.dev.local

  • Binding:

    • Type: http

    • Hostname: sc.dev.local

    • Port: 80

✔ Bước 3: Add host file

Mở Notepad (Run as Admin)

 
127.0.0.1 sc.dev.local 127.0.0.1 sc.cd.dev.local 127.0.0.1 identityserver.dev.local

3️⃣ Cấu hình CM

Trong thư mục Sitecore CM:

web.config

Không cần chỉnh nhiều, nhưng cần kiểm tra:

 
<compilation debug="true" />

Chỉ bật debug ở local CM, không bật ở CD.

App_Config\Include\Z.Sitecore.Environment.config (tự tạo)

 
<configuration> <sitecore> <settings> <setting name="Role:define" value="ContentManagement" /> </settings> </sitecore> </configuration>

4️⃣ Cấu hình CD

CD không chạy Sitecore admin, không dùng Experience Editor, không dùng Indexing UI.

✔ Disable admin

Trong CD thêm cấu hình:

 
<sitecore> <settings> <setting name="Role:define" value="ContentDelivery" /> </settings> <sites> <site name="shell"> <patch:attribute name="enable">false</patch:attribute> </site> <site name="admin"> <patch:attribute name="enable">false</patch:attribute> </site> </sites> </sitecore>

✔ Tắt debug view

 
<compilation debug="false" />

✔ Tắt Experience Editor

 
<setting name="ExperienceEditor.Enabled" value="false" />

✔ Tắt xConnect communication nếu CD không cần


5️⃣ Cấu hình Identity Server

Project identityserver cũng tạo website riêng trên IIS.

Binding:

 
identityserver.dev.local

Cập nhật config trong CM:

identityServerAuthority trong Sitecore.Owin.Authentication.IdentityServer.config

 
<setting name="IdentityServer.Authority" value="https://identityserver.dev.local" />

Cập nhật client secret (nếu cần)


6️⃣ Cấu hình Application Pool

✔ .NET version

  • Sitecore 10+: .NET Framework 4.7.2

  • Managed pipeline: Integrated

✔ Disable "Start Mode: OnDemand"

Nên set:

 
startMode = AlwaysRunning


Application Pool → Advanced → Idle Time-out = 0

Để tránh Web App tự tắt.


7️⃣ Cấu hình Permissions (quyền folder)

Sitecore cần quyền:

  • Modify cho các folder:

    • /App_Data

    • /sitecore modules

    • /temp

    • /upload

    • /logs

Gán quyền cho user IIS_IUSRS hoặc ApplicationPoolIdentity.


8️⃣ Cấu hình URL Rewrite (quan trọng)

CD environments thường cần rewrite để SEO-friendly URLs.

Ví dụ rewrite bỏ .aspx:

 
<rule name="RemoveASPX" stopProcessing="true"> <match url="(.*)\.aspx$" /> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> </rule>

Hoặc redirect HTTP → HTTPS.


9️⃣ Cấu hình cho Sitecore Media URLs

Thêm rewrite rule:

 
/-/media/ /-/item/v1/

Để không bị route sai.


🔟 Troubleshooting các lỗi IIS thường gặp

❌ 500.19 – Cannot read configuration file

→ Sai syntax XML trong config
→ Thiếu module IIS (.NET Extensibility, ISAPI, ASP.NET)

❌ 500.11 – Application restarting

→ App pool bị recycle (Idle timeout)

❌ 404 – Item not found

→ Chưa đúng host
→ Sai binding
→ Chưa publish content lên CD

❌ Identity Server redirect loop

→ Sai config IdentityServer.Authority
→ HTTPS chưa bật


📘 Bài tập thực hành Ngày 25

Bài 1

Tạo CM site
Binding: sc.dev.local
Test vào /sitecore/login

Bài 2

Tạo CD site
Binding: sc.cd.dev.local
Disable admin UI
Kiểm tra website hiển thị OK

Bài 3

Tạo Identity Server
Binding: identityserver.dev.local

Chạy Sitecore CM → Kiểm tra redirect sang Identity Server → Login thành công.

Donald Trump

Để trở thành người chiến thắng, bạn cần biết khi nào là đủ. Đôi khi trong cuộc sống, bạn phải từ bỏ cuộc chiến và chuyển sang mục tiêu mới mang lại hiệu quả hơn

Related Post