Nginx Tomcat負載均衡

創建Bin目錄,作爲所有執行文件的存放目錄,

下載Nginx穩定版源碼

http://nginx.org/en/download.html


下載OpenSSL源碼

https://www.openssl.org/source/


下載PCRE源碼

http://www.pcre.org/


下載Zlib源碼

http://www.zlib.net/


下載nginx-upstream-jvm-route

https://github.com/xiamaoxuan/nginx-upstream-jvm-route


解壓Nginx,並將其他源碼解壓後拖入Nginx中,(以下操作中的/Users/libo/Bin/均替換爲你實際目錄

進入pcre目錄, 執行./configure --enable-utf8 && sudo make && make install, 成功後返回上層目錄

執行:patch -p0 < /Users/libo/Bin/nginx-1.10.2/niginx-jvm-route/jvm_route.patch

執行:

./configure --with-poll_module --without-http_gzip_module --without-http_rewrite_module --without-http_proxy_module --with-http_ssl_module  --with-http_stub_status_module  --with-openssl=./openssl-1.1.0c  --with-zlib=./zlib-1.2.8  --add-module=./nginx-upstream-jvm-route --user=www --group=www


如果是MacOS, 修改objs/Makefile, 找到

./openssl-1.1.0c/.openssl/include/openssl/ssl.h:    objs/Makefile
    cd ./openssl-1.1.0c \
    && if [ -f Makefile ]; then $(MAKE) clean; fi \
    && ./config --prefix=/Users/libo/Bin/nginx-1.10.2/./openssl-1.1.0c/.openssl no-shared  \
    && $(MAKE) \
    && $(MAKE) install_sw LIBDIR=lib

將config改爲:

Configure darwin64-x86_64-cc

再make  並 make install




nginx命令

1. 啓動 Nginx          /usr/local/nginx/sbin/nginx

poechant@ubuntu:sudo ./sbin/nginx

2. 停止 Nginx

poechant@ubuntu:sudo ./sbin/nginx -s stop
poechant@ubuntu:sudo ./sbin/nginx -s quit

-s都是採用向 Nginx 發送信號的方式。
3. Nginx 重載配置

poechant@ubuntu:sudo ./sbin/nginx -s reload

上述是採用向 Nginx 發送信號的方式,或者使用:

poechant@ubuntu:service nginx reload

4. 指定配置文件

poechant@ubuntu:sudo ./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c表示configuration,指定配置文件。
5. 查看 Nginx 版本

有兩種可以查看 Nginx 的版本信息的參數。第一種如下:

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -v
nginx: nginx version: nginx/1.0.0

另一種顯示的是詳細的版本信息:

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built by gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
nginx: TLS SNI support enabled
nginx: configure arguments: --with-http_ssl_module --with-openssl=/home/luming/openssl-1.0.0d/

6. 檢查配置文件是否正確

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -t
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
2012/01/09 16:45:09 [emerg] 23898#0: open() "/usr/local/nginx/logs/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

如果出現如上的提示信息,表示沒有訪問錯誤日誌文件和進程,可以sudo(super user do)一下:

poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

如果顯示如上,則表示配置文件正確。否則,會有相關提示。
7. 顯示幫助信息

poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -h

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章