相關目錄html
# 主目錄 /usr/local/nginx # 配置文件路徑 /usr/local/nginx/conf/nginx.conf # linux 安裝目錄\conf\nginx.conf # Windows # 靜態文件路徑 /usr/local/nginx/html/
啓動linux
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf # 看到以下顯示說明啓動成功 ''' nginx.conf syntax is ok nginx.conf test is successful '''
重啓nginx
/usr/local/nginx/sbin/nginx -s reload
查看進程是否啓動負載均衡
ps -ef|grep nginx
查看端口號是否佔用ide
netstat -tunlp|grep 端口號
強制中止網站
pkill -9 nginx
驗證nginx配置文件是否正確spa
/usr/local/nginx/sbin/nginx -t # 看到以下顯示說明配置文件正確 ''' nginx.conf syntax is ok nginx.conf test is successful '''
基於域名的虛擬主機code
經過不一樣的域名區分不一樣的虛擬主機,基於域名的虛擬主機是企業應用最廣的虛擬主機類型,幾乎全部對外提供服務的網站使用的都是基於域名的主機server
配置:修改nginx配置文件配置多域名,重啓nginx服務,建立對應的不一樣站點目錄並上傳站點文件,也可都使用一個站點目錄,經過多域名來訪問htm
server{ listen 80; server_name www.aaa.com; location / { root html/aaa; index index.html index.htm; } } server{ listen 80; server_name www.bbb.com; location / { root html/bbb; index index.html index.htm; } } server{ listen 80; server_name www.ccc.com; location / { root html/ccc; index index.html index.htm; } }
基於端口的虛擬主機
經過不一樣的端口來區分不一樣的虛擬主機,此類虛擬主機對應的企業應用主要爲公司內部的網站,例如:一些不但願直接對外提供用戶訪問的網站後臺等,訪問基於端口的虛擬主機,地址裏要帶有端口號,例如http://www.test.com:81 http://www.test.com:82等
server{ listen 80; server_name localhost; location / { root html/aaa; index index.html index.htm; } } server{ listen 81; server_name localhost; location / { root html/bbb; index index.html index.htm; } } server{ listen 82; server_name localhost; location / { root html/ccc; index index.html index.htm; } }
基於IP的虛擬主機
經過不一樣的IP區分不一樣的虛擬主機,此類虛擬主機對應的企業應用很是少見,通常不一樣的業務須要使用多IP的場景都會在負載均衡上進行IP綁定。
server{ listen 10.0.0.7:80; server_name www.aaa.com; location / { root html/aaa; index index.html index.htm; } } server{ listen 10.0.0.8:80; server_name www.bbb.com; location / { root html/bbb; index index.html index.htm; } } server{ listen 10.0.0.9:80; server_name www.ccc.com; location / { root html/ccc; index index.html index.htm; } }
其餘配置
修改上傳文件大小限制
Nginx 默認是對上傳的文件大小有限制的,咱們能夠修改相應配置來修改對文件大小的限制
# 在http{}段落增長以下參數 client_max_body_size 20M; # 20M能夠換爲任何大小