上一篇已经安装好了nginx
前提你有域名,服务器有外网IP,不然就是扯蛋
配置tomcate和绑定域名
找到nginx/conf/nginx.conf,做如下关键配置:
#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;
upstream erp {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name erp.dgrxs.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://erp;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#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 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;
# }
#}
}
Tomcate修改
<Host name="www.hehe.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="../webapps/testweb" debug="0" reloadable="true"/> </Host>
https配置
运行 /usr/local/nginx/sbin/nginx -V ,如果没有 最后一行说明ssl没弄好
[root@61E6v9-server logs]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
1.2 Nginx开启SSL模块
切换到源码包:
1 |
|
配置信息就应该这样写:
1 |
|
|
线上加入图片压缩功能
./configure --prefix=/usr/local/nginx \--with-http_stub_status_module \--with-http_ssl_module \--with-http_image_filter_module
make & make install
运行上面的命令即可,等配置完
配置完成后,运行命令 make
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
1 |
|
然后启动nginx,仍可以通过命令查看是否已经加入成功
1 |
|
在原本的基础上加上这个配置
server {
listen 443 ssl;
server_name www.dgrxs.com; #填写绑定证书的域名
ssl_certificate /usr/local/nginx/conf/crt/cert-151_www.dgrxs.com.crt;# 当前配置文件夹下建个目录存放证书
ssl_certificate_key /usr/local/nginx/conf/crt/cert-151_www.dgrxs.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://www;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; #防止重定向后变成http
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
tomcate在原本基础上加2个地方
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" proxyPrort="443"
disableUploadTimeout="false" />
在Engine中加上,原本默认的不要管,只管在Engine中加就可以了
<Valve className="org.apache.catalina.valves.RemoteIpValve"
protocolHeaderHttpsValue="https" remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto" />
配置完,一定要重启nginx,不是reload,是kill再启动,和tomcate