需要的预置环境:
1.openssl-fips-2.0.5.tar.gz
2.pcre-8.32.tar.gz
3.zlib-1.2.7.tar.gz
4.nginx-1.2.6.tar.gz
1)root用户mkdir目录/usr/local/nginx/
2)将这4个包放置在该目录下,并tar -zxvf *.tar.gz解压
3)安装openssl-fips-2.0.5,
3.1)cd /usr/local/nginx/openssl-fips-2.0.5/
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登录页面),那么反向代理访问不到那么就会导致超时链接错误。