首頁 運維 Nginx nginx伺服器多站點怎麼配置

nginx伺服器多站點怎麼配置

May 18, 2023 am 11:29 AM
nginx

1、首先要找到nginx 設定檔之所在,阿里雲上的nginx.conf 檔案上 /alidata/server/nginx-1.4.4/conf 中。

2、然後在conf目錄下建立一個vhosts 目錄,  這個目錄是用來存放不同網站的設定檔的。

3、然後呢, 在nginx.conf 最後加入一行include /alidata/server/nginx/conf/vhosts/*.conf;

user www www; 
worker_processes 1; 
 
error_log /alidata/log/nginx/error.log crit; 
pid    /alidata/server/nginx/logs/nginx.pid; 
 
#specifies the value for maximum file descriptors that can be opened by this process.  
worker_rlimit_nofile 65535; 
 
events  
{ 
 use epoll; 
 worker_connections 65535; 
} 
 
 
http { 
  include    mime.types; 
  default_type application/octet-stream; 
 
  #charset gb2312; 
 
  server_names_hash_bucket_size 128; 
  client_header_buffer_size 32k; 
  large_client_header_buffers 4 32k; 
  client_max_body_size 8m; 
 
  sendfile on; 
  tcp_nopush   on; 
 
  keepalive_timeout 60; 
 
  tcp_nodelay on; 
 
  fastcgi_connect_timeout 300; 
  fastcgi_send_timeout 300; 
  fastcgi_read_timeout 300; 
  fastcgi_buffer_size 64k; 
  fastcgi_buffers 4 64k; 
  fastcgi_busy_buffers_size 128k; 
  fastcgi_temp_file_write_size 128k; 
 
  gzip on; 
  gzip_min_length 1k; 
  gzip_buffers   4 16k; 
  gzip_http_version 1.0; 
  gzip_comp_level 2; 
  gzip_types    text/plain application/x-javascript text/css application/xml; 
  gzip_vary on; 
  #limit_zone crawler $binary_remote_addr 10m; 
  log_format '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 
          
  # 加入下面一行 表示将 vhosts 下面所有的 conf 文件包含进来 
  include /alidata/server/nginx/conf/vhosts/*.conf; 
}
登入後複製

4、然後,就是在vhosts 目錄下寫你對應網站的conf 檔案了。下面給出一個範例

server { 
  listen    80; 
  # 这个表示 网站域名, 可以是二级甚至多级域名 
  server_name localhost demo.com www.demo.com test.demo.com; 
 
  # 表示默认索引文件 
  index index.html index.htm index.php; 
   
  # 该站点对应的网站根目录所在 
  root /alidata/www/demo; 
 
  location ~ .*\.(php|php5)?$ 
  { 
    #fastcgi_pass unix:/tmp/php-cgi.sock; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    include fastcgi.conf; 
  } 
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 
  { 
    expires 30d; 
  } 
  location ~ .*\.(js|css)?$ 
  { 
    expires 1h; 
  } 
 
  # 伪静态规则 
  include /alidata/server/nginx/conf/rewrite/phpwind.conf; 
  access_log /alidata/log/nginx/access/phpwind.log; 
}
登入後複製

5、如果還要繼續添加, 直接複製檔案。然後修改一下 server_name, root, 和access_log(如果有必要的話) 就ok了。

6、然後,不要立刻重啟nginx,應該要先測試一下nginx 設定檔是否正常. 找到nginx 的 sbin目錄。注意, 這個地方是nginx 的sbin 目錄(這個目錄與nginx 的conf 目錄是同級目錄)。 linux 下有許多與sbin同名的目錄。容易搞錯。在阿里雲端伺服器上一般預設的目錄是 /alidata/server/nginx-1.4.4/sbin。

nginx伺服器多站點怎麼配置

7、輸入cd /alidata/server/nginx-1.4.4/sbin,然後輸入  ./nginx -t ,如果控制台顯示下面兩行,則表示配置成功了,否則請根據提示繼續檢查設定檔。

nginx: the configuration file /alidata/server/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /alidata/server/nginx/conf /nginx.conf test is successful

nginx伺服器多站點怎麼配置

8、設定成功之後, 就需要重新啟動nginx 伺服器。在sbin目錄下輸入指令:./nginx -s reload, 然後整個過程就完成了。

另外, 總結nginx 的幾個常用指令:


./nginx
登入後複製

./nginx -s reload
登入後複製

重啟  

#

ps -ef | grep nginx   # 查询nginx主进程号
登入後複製

關機 

./nginx -t
登入後複製

從容停止   kill -quit 主行程號碼 


快速停止   kill -term 主程式號碼 


強制停止   kill -term 主程式號碼 


強制停止9 nginx 


若nginx.conf配置了pid檔案路徑,如果沒有,則在logs目錄下 


kill -訊號類型'/usr/local/nginx/ logs/nginx.pid'  

#######判斷設定檔是否正確 ######rrreee

以上是nginx伺服器多站點怎麼配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
威爾R.E.P.O.有交叉遊戲嗎?
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

怎麼查看nginx是否啟動 怎麼查看nginx是否啟動 Apr 14, 2025 pm 01:03 PM

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

nginx怎麼配置雲服務器域名 nginx怎麼配置雲服務器域名 Apr 14, 2025 pm 12:18 PM

在雲服務器上配置 Nginx 域名的方法:創建 A 記錄,指向雲服務器的公共 IP 地址。在 Nginx 配置文件中添加虛擬主機塊,指定偵聽端口、域名和網站根目錄。重啟 Nginx 以應用更改。訪問域名測試配置。其他注意事項:安裝 SSL 證書啟用 HTTPS、確保防火牆允許 80 端口流量、等待 DNS 解析生效。

怎麼啟動nginx服務器 怎麼啟動nginx服務器 Apr 14, 2025 pm 12:27 PM

啟動 Nginx 服務器需要按照不同操作系統採取不同的步驟:Linux/Unix 系統:安裝 Nginx 軟件包(例如使用 apt-get 或 yum)。使用 systemctl 啟動 Nginx 服務(例如 sudo systemctl start nginx)。 Windows 系統:下載並安裝 Windows 二進製文件。使用 nginx.exe 可執行文件啟動 Nginx(例如 nginx.exe -c conf\nginx.conf)。無論使用哪種操作系統,您都可以通過訪問服務器 IP

linux怎麼啟動nginx linux怎麼啟動nginx Apr 14, 2025 pm 12:51 PM

在 Linux 中啟動 Nginx 的步驟:檢查 Nginx 是否已安裝。使用 systemctl start nginx 啟動 Nginx 服務。使用 systemctl enable nginx 啟用在系統啟動時自動啟動 Nginx。使用 systemctl status nginx 驗證啟動是否成功。在 Web 瀏覽器中訪問 http://localhost 查看默認歡迎頁面。

nginx在windows中怎麼配置 nginx在windows中怎麼配置 Apr 14, 2025 pm 12:57 PM

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

nginx403怎麼解決 nginx403怎麼解決 Apr 14, 2025 am 10:33 AM

如何解決 Nginx 403 Forbidden 錯誤?檢查文件或目錄權限;2. 檢查 .htaccess 文件;3. 檢查 Nginx 配置文件;4. 重啟 Nginx。其他可能原因還包括防火牆規則、SELinux 設置或應用程序問題。

linux怎麼查看nginx是否啟動 linux怎麼查看nginx是否啟動 Apr 14, 2025 pm 12:48 PM

在 Linux 中,使用以下命令檢查 Nginx 是否已啟動:systemctl status nginx根據命令輸出進行判斷:如果顯示 "Active: active (running)",則 Nginx 已啟動。如果顯示 "Active: inactive (dead)",則 Nginx 已停止。

怎麼解決nginx跨域問題 怎麼解決nginx跨域問題 Apr 14, 2025 am 10:15 AM

解決 Nginx 跨域問題有兩種方法:修改跨域響應頭:添加指令以允許跨域請求,指定允許的方法和頭,以及設置緩存時間。使用 CORS 模塊:啟用模塊並配置 CORS 規則,允許跨域請求、方法、頭和設置緩存時間。

See all articles