須要的預置環境:php
1.openssl-fips-2.0.5.tar.gz html
2.pcre-8.32.tar.gz linux
3.zlib-1.2.7.tar.gznginx
4.nginx-1.2.6.tar.gzweb
1)root用戶mkdir目錄/usr/local/nginx/shell
2)將這4個包放置在該目錄下,並tar -zxvf *.tar.gz解壓tomcat
3)安裝openssl-fips-2.0.5,session
3.1)cd /usr/local/nginx/openssl-fips-2.0.5/app
3.2)./config負載均衡
3.3)make
3.4)make install
4)安裝pcre-8.32和zlib-1.2.7用*代替
4.1)cd /usr/local/nginx/*/
4.2)./configure
4.3)make
4.4)make install
5)安裝nginx-1.2.6
5.1)cd /usr/local/nginx/nginx-1.2.6/
5.2)
./configure --with-pcre=../pcre-8.32 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.5
5.3)make
5.4)make install
6)檢測下安裝是否成功
這種狀況表示是對的。
而後查看一下/usr/local/nginx/conf/nginx.conf,主要想看看端口號,
在/usr/local/nginx/conf/路徑下有一個nginx.conf.default,其實我是用的這個,「原生態」的這個文件以下,
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 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; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
能夠看到,端口號listen 80,所以,我測試下訪問http://210.10.5.189:80/,5.189就是這臺部署nginx服務的linux紅帽6
因此部署是正確的。
其實這裏的頁面是目錄/usr/local/nginx/html下面的,因此默認的狀態靜態頁面都是在此目錄下
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
7)修改配置「動靜分離」以實現負載均衡
參照PHP反向代理的配置,我配置了Java反向代理,意思也就是.do和.jsp須要反向代理,地址爲5.102:8080,
修改完配置須要先停服務,再重啓服務,
停服務:/usr/local/nginx/sbin/nginx -s stop
起服務:/usr/local/nginx/sbin/nginx
測試以下,
若是5.102的服務沒開啓(5.102這裏我用的tomcat6,也就很普通的一個jsp登陸頁面),那麼反向代理訪問不到那麼就會致使超時連接錯誤。