$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install nginx
$ sudo apt-get install fcgiwrap php5-fpm php5-xcache php5-mysql php5-pgsql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
2. 創建要放置網頁檔案的磁碟路徑(放在/var/www/之下)
$ sudo mkdir -p /var/www/yourdomain1.com/html
$ sudo mkdir -p /var/www/yourdomain2.com/html
$ sudo chown -R www-data:www-data /var/www/yourdomain1.com/html
$ sudo chown -R www-data:www-data /var/www/yourdomain2.com/html
$ sudo chmod -R 755 /var/www
3. 編寫 index.html
$ sudo vi /var/www/yourdomain1.com/html/index.html
$ sudo vi /var/www/yourdomain2.com/html/index.html
範例如下:
<html lang="zh-TW">
<head>
<title>page title</title>
<script src="my-javascript-file.js"></script>
<link href="my-css-file.css" rel="stylesheet"></link>
</head>
<body>
<!-- 網頁內容就放在body內吧 -->
Hello, yourdomain1.com <!-- 或是 yourdomain2.com -->
</body>
</html>
4. 設定第一個網站設定檔
$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/yourdomain1.com
$ sudo vi /etc/nginx/sites-available/yourdomain1.com
修改設定檔內容:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/yourdomain1.com/html;
index index.html index.htm index.php;
server_name yourdomain1.com www.yourdomain1.com;
location / {
try_files $uri $uri/ =404;
}
}
5. 設定第二個網站設定檔
$ sudo cp /etc/nginx/sites-available/yourdomain1.com /etc/nginx/sites-available/yourdomain2.com
$ sudo vi /etc/nginx/sites-available/yourdomain2.com
修改設定檔內容,注意listen設定有些不同:
server {
listen 80;
listen [::]:80;
root /var/www/yourdomain2.com/html;
index index.html index.htm index.php;
server_name yourdomain2.com www.yourdomain2.com;
location / {
try_files $uri $uri/ =404;
}
}
6. 讓兩個網站的設定檔案生效
$ sudo ln -s /etc/nginx/sites-available/yourdomain1.com /etc/nginx/sites-enabled/
$ sudo ln -s /etc/nginx/sites-available/yourdomain2.com /etc/nginx/sites-enabled/
7. 移除預設設定檔案
$ sudo rm /etc/nginx/sites-enabled/default
8. 修改 nginx.conf
$ sudo vi /etc/nginx/nginx.conf
將 server_names_hash_bucket_size: 64; 前面的註解符號 # 移除,然後存檔離開
9. 重新啟動 nginx
$ sudo service nginx restart
10. 修改 hosts,新增網站資料
$ sudo vi /etc/hosts
新增
192.168.1.80 yourdomain1.com
192.168.1.80 yourdomain2.com
11. 設定開機時,自動啟動nginx服務
$ sudo update-rc.d nginx defaults
#
沒有留言:
張貼留言