1. 程式人生 > >CocosCreator開發筆記(2)-Linux系統用Nginx搭建Web釋出伺服器

CocosCreator開發筆記(2)-Linux系統用Nginx搭建Web釋出伺服器

上文介紹了用簡單的Python命令搭建CocosCreator的Web釋出伺服器,這一般在開發除錯中使用。如果是用於正式伺服器,則還是需要用專業的Web伺服器軟體,以滿足高效能、靈活、穩定的商用需求。

Nginx簡介

Nginx是一款高效能、輕量級的HTTP伺服器、反向代理伺服器。和Apache相比具有佔用記憶體少、穩定性高的優點,它最常用的用途是提供反向代理服務,使用方法非常簡單且靈活,很適合用來做Web伺服器。

Nginx安裝

注:以下命令需要root使用者許可權。

以CentOS7為例,因為yum源不提供nginx的安裝,需要自己新增。步驟如下:

1 新增安裝源

2 安裝

yum install -y nginx

3 啟動

systemctl start nginx.service
檢視狀態
systemctl status nginx.service
開機啟動
systemctl enable nginx.service

Nginx配置

網站檔案存放預設目錄
/usr/share/nginx/html
網站預設站點配置
/etc/nginx/conf.d/default.conf
自定義Nginx站點配置檔案存放目錄
/etc/nginx/conf.d/
Nginx全域性配置
/etc/nginx/nginx.conf

Nginx使用

例如,當前伺服器域名是game.123.com,想在6666埠新增一個Web伺服器,指向目錄為/home/myweb/html,則只要在 /etc/nginx/conf.d/default.conf 中增加如下一段即可:

server {
listen 6666;
server_name game.123.com;
location / {
root /home/myweb/html;
index index.html index.html;
}
}

配置好後,使用命令 systemctl restart nginx.service 重啟Nginx,然後在客戶端使用 game.123.com:6666 訪問即可。