linux上安裝nginx

來源:互聯網
上載者:User
---------安裝
先安裝依賴
yum -y install openssl openssl-devel
yum -y install pcre-devel
下載nginx
wget http://nginx.org/download/nginx-1.10.0.tar.gz
安裝
先解壓
tar -zxvf nginx-1.10.0.tar.gz
再編譯
cd nginx-1.10.0
./configure --prefix=/usr/local/nginx
make
make install
啟動
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止
先查看進程號
ps -ef |grep nginx
root 12901 1 0 11:26 ? 00:00:00 nginx: master process ./nginx
nobody 12902 12901 0 11:26 ? 00:00:00 nginx: worker process
再停止
從容停止:kill -s QUIT 12901
快速停止:kill -s TERM 12901/ kill -s INT 12901
強制停止:killall nginx
重啟
驗證設定檔是否正確,
方式一:必須進入/usr/local/nginx/sbin/ 執行 ./nginx -t
方式二:/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
開始重啟
方法一:必須進入/usr/local/nginx/sbin/ 執行 ./nginx -s reload
方法二:kill -HUP 主進稱號
搭建nginx+tomcat環境
在nginx設定檔中添加以下配置(簡單的例子)
nginx我安裝在目錄下:/usr/local/nginx/
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
charset UTF-8;
sendfile on;
access_log off;
error_log logs/host.error.log crit;
keepalive_timeout 65;
gzip on;
gzip_min_length 1000;
gzip_comp_level 4;
gzip_types text/plain text/css text/xml application/json application/x-javascript;
open_file_cache max=655350 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;

#停機標誌,不會被訪問到
#server 192.168.239.134:8080 down;
#備份機,所有的非備份機掛掉了才啟用
#server 192.168.239.134:8080 backup;
upstream tomcats {
fair;
server 192.168.239.134:8080 backup;
server 192.168.239.135:8080 weight=5;
server 192.168.239.136:8080 weight=2 max_fails=2 fail_timeout=60s;
}
server {
listen 80;
server_name 192.168.239.135;
access_log logs/host.access.log combined;
location ~ \.(jsp|jspx|do)$ {
##root /picclife/data0/www; #tomcat的部署路徑,被我改了
index index.jsp index.jspx index.do;
##proxy_pass http://192.168.239.134:8080; #tomcat服務的地址
proxy_pass http://tomcats;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
---------負載平衡策略
1、none 輪詢方式(一次一次輪),預設
2、可以通過權重weight來改變輪詢(預設為1),權重值越高,被分配的請求越多
3、ip_hash 根據使用者的ip地址進行hash運算得到hash值,綁定到某個伺服器上,
後續使用者的ip不變就會鎖定在某個伺服器上,此時權重就失效了
4、fair 第三方的,根據自己的演算法,得到伺服器的負載情況,進行請求分配
5、url_hash 第三方的,根據請求的url進行hash運算,來綁定伺服器
安裝第三方模組
1、下載gnosek-nginx-upstream-fair-a18b409.tar.gz
2、解壓tar -zxvf gnosek-nginx-upstream-fair-a18b409.tar.gz
3、配置,進入nginx的解壓目錄
./configure --prefix=/usr/local/nginx --add-module=/picclife/soft/nginx-upstream-fair
4、編譯,不安裝,因為之前我們安裝了nginx
make
5、進入objs目錄
[root@zhanglw-5 objs]# ls
addon autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
6、替換nginx,之前我們的nginx安裝在了/usr/local/nginx目錄下了
cp nginx /usr/local/nginx/sbin/

替換前要停止nginx,否則替換不了

以上就介紹了 linux上安裝nginx,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.