#nginx 監聽原理 先監聽端口 --> 再配置域名 -->匹配到就訪問local 否則 沒有匹配到域名就默認訪問第一個監聽端口的local地址
# vi nginx.conf user nobody nobody; # 運 nginx的所屬組和所有者 worker_processes 2; # 開啟兩個 nginx工作進程,一般幾個 CPU核心就寫幾 error_log logs/error.log notice; # 錯誤日志路徑 pid logs/nginx.pid; # pid 路徑 events { worker_connections 1024; # 一個進程能同時處理1024個請求 } http { include mime.types; default_type application/octet-stream; log_format main $remote_addr – $remote_user [$time_local] “$request” $status $body_bytes_sent “$http_referer” $http_user_agent” “$http_x_forwarded_for” ; access_log logs/access.log main; # 默認訪問日志路徑 sendfile on; keepalive_timeout 65; # keepalive超市時間 # 開始配置一個域名,一個server配置段一般對應一個域名 server { listen 80; # 監聽端口() # 在本機所有ip上監聽80,也可以寫為192.168.1.202:80,這樣的話,就只監聽192.168.1.202 上的80口 server_name www.heytool.com; # 域名 root /www/html/www.heytool.com; # 站點根目錄(程序目錄) index index.html index.htm; # 索引文件
# 可以有多個 location
location / {
#proxy_pass www.baidu.com # 跳到 百度頁面 (網址) root /www/html/www.heytool.com; # 站點根目錄(程序目錄) (本地的路徑) }
error_page 500 502 503 504 /50x.html; # 定義錯誤頁面,如果是500錯誤,則把站點根目錄下的50x.html返回給用戶 location = /50x.html { root /www/html/www.heytool.com; } }
#nginx 監聽原理 先監聽端口 --> 再配置域名 -->匹配到就訪問local 否則 沒有匹配到域名就默認訪問第一個監聽端口的local地址
//看到ok和successful,說明配置文件沒問題
# /usr/local/nginx-1.0.6/sbin/nginx –t
nginx: the configuration file /usr/local/ nginx-1.0.6/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/ nginx-1.0.6/conf/nginx.conf test is successful
#啟動 nginx
# /usr/local/nginx-1.0.6/sbin/nginx
#重啟 nginx
# /usr/local/nginx-1.0.6/sbin/nginx -s reload