nginx是安装在Linux下面的;
安装nginx参考了一下下面这个文档
http://www.cnblogs.com/Netsharp/p/5890170.html
如果需要加载https模块,
需要先安装openssl,以及openssl devel
yum -y install openssl openssldevel
nginx编译和安装时,需要把--with-http_ssl_module加在./configure后面;
如果需要加载gzip模块,需要把--with-http-gzip-static-module加在./configure后面;
#./configure --with-http_ssl_module
然后根据上面的那个文档就可以安装成功;
nginx的几个操作:
1.在nginx的sbin目录下面,使用sudo ./nginx -V可以查看nginx的加载项,如果加载了gzip,https,在这里就可以看出来
2.sudo ./nginx -t,在重启nginx前,检查nginx.conf配置文件语法是否正确;
3.sudo ./nginx -s reload ,是重新加载nginx的配置文件,做到平滑重启的效果;
4.sudo ./nginx -s reopen ,是重启nginx;
5.sudo ./nginx -s stop, 是关闭nginx;
6.sudo ./nginx, 启动nginx.
7.tail -f /usr/local/nginx/logs/*.log ,可以实时的打印出log日志;
下面是nginx.conf文件的内容:
user yyyadmin yyyadmin;
worker_processes 2;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
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压缩功能设置
gzip on; #开启gzip压缩输出
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_comp_level 2; #压缩等级
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
gzip_vary on;
# http_proxy 设置
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 75;
proxy_read_timeout 75;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /usr/local/nginx/proxy_temp 1 2;
# 设定负载均衡后台服务器列表
#http配置
upstream tomcat80 {
server 127.0.0.1:8080 max_fails=2 fail_timeout=30s ;
}
#https配置
upstream tomcat443 {
server 127.0.0.1:8443 max_fails=2 fail_timeout=30s ;
}
server {
listen 80;
server_name localhost;
server_tokens off;
charset utf-8;
access_log logs/host.access.log main;
location / {
#root html;
index index.html index.htm;
proxy_pass http://tomcat80;
proxy_redirect off;
# 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
#静态文件,nginx自己处理,不去backend请求tomcat
location ~* \.(tff|html|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root html;
expires off;
}
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;
}
location = / {
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;
#}
}
#https server配置
server{
listen 443;
server_name localhost;
ssl on;
ssl_certificate /home/yyyadmin/nginx_ssl/213962072070403.pem;
ssl_certificate_key /home/yyyadmin/nginx_ssl/213962072070403.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass https://tomcat443;
proxy_set_header Host $host:443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#静态文件,nginx自己处理,不去backend请求tomcat
location ~* \.(tff|html|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root html;
expires off;
}
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;
}
location = / {
root html;
}
}
下面是tomcat的https配置:
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="/home/yyyadmin/tomcat-ssl/213971683120403.pfx"
keystoreType="PKCS12"
keystorePass="213971683120403"
sslEnabledProtocols="TLSv1"
clientAuth="false" sslProtocol="TLS" />
# 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 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
记录几篇文章
http://blog.csdn.net/hellochenlian/article/details/44655547
Nginx+Tomcat+SSL免费证书配置:
http://www.linuxidc.com/Linux/2015-06/119249.htm