官網:http://nginx.org/en/download....
windows系統下打開官網下載一個linux系統的nginx,以後再傳到linux系統中,這樣比直接在yum中下載的版本更新些;html
上傳到指定目錄中/usr/local/src/linux
命令:tar -xvf 包名
nginx
把壓縮包移動到指定目錄下或刪除,software目錄是爲了統一管理壓縮包而建立的目錄windows
1)在nginx-source的根目錄中執行命令: ./configure
完成
2)在nginx-source的根目錄中執行命令: make
[root@localhost nginx-source]# make
3)在nginx-source的根目錄中執行命令: make install
[root@localhost nginx-source]# make install
tomcat
命令:whereis nginx
服務器
1)進入nginx/sbin目錄中
2)在sbin目錄下執行啓動命令啓動命令: ./nginx
重啓命令: ./nginx -s reload
關閉命令: ./nginx -s stop
負載均衡
1)實現圖片反向代理
2)實現tomcat負載均衡實現測試
位置:/usr/local/nginx/conf/nginx.conf
打開nginx.conf文件
修改配置文件spa
`server { #配置圖片代理服務器 http://image.jt.com:80 listen 80; #設置域名 server_name image.jt.com; location / { #存放圖片的目錄 #root D:/JT-SOFT/images; root /usr/local/src/images; } } #配置商品後臺服務器 server{ listen 80; #設置域名 server_name manage.jt.com; location / { #代理真實服務器地址 #proxy_pass http://localhost:8091; #映射到集羣 #proxy_pass http://jtWindows; proxy_pass http://jtLinux; } } #配置tomcat服務器集羣 1.默認 輪詢策略 2.權重策略 3.ip_hash策略 upstream jtWindows { #ip_hash; down 標識宕機 backup 備用機 #max_fails=1 表示最大的失敗次數 #fail_timeout=60s 若是訪問不通,則在60秒內,不會再次訪問故障機 server 127.0.0.1:8081 max_fails=1 fail_timeout=60s; server 127.0.0.1:8082 max_fails=1 fail_timeout=60s; server 127.0.0.1:8083 max_fails=1 fail_timeout=60s; } upstream jtLinux { server 192.168.126.129:8081; server 192.168.126.129:8082; server 192.168.126.129:8083; }
`3d
重啓命令: ./nginx -s reload
使用域名訪問服務器須要把域名進行解析,hosts能夠對本機的域名進行解析,能知足測試的需求,但商品一上線就須要花錢註冊域名了,hosts就不能夠了;
修改的時候須要用到超級管理員的權限,打開的方式用以管理員方式打開;
1)直接用關閉命令關;關閉命令: ./nginx -s stop
2)查出nginx進程,關閉進程
查nginx進程命令:ps -ef | grep nginx*
關進程命令:
普通型:kill 進程號
進程執行完畢關掉:kill -9 進程號
立馬關掉進程:kill -15 進程號