nginx配置ssl协议https +tomcat 非80/443端口反向代理的配置方式

--开始

Nginx增加以下配置

proxy_set_header Host $host:$server_port; 非80端口 ,用80端口时 不需要$server_port

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;

--结束


-----本人server示例 开始-----

nginx.conf

#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
	
	include nixcraft.in.conf;
}

nixcraft.in.conf

upstream ndgweb {
    server 192.168.168.168:8037;
}
upstream gwapp{
    server 192.168.168.125:8101;
}

server {
    access_log  logs/access.log;
    error_log   logs/error.log;
    index       index.html;
    root        /usr/local/nginx/html;
    server_name www.j*s*****o.com;
    listen 8100 ssl;
    ssl on;
    ssl_certificate      ssl.cer;
    ssl_certificate_key  ssl.key;

    ## Only allow these request methods
    if ($request_method !~ ^(GET|HEAD|POST)$ ) {
        return 444;
    }
 
    ## PROXY - Web
    location / {
        proxy_pass  http://ndgweb;
        proxy_ignore_headers   Expires Cache-Control;
 
        proxy_set_header        Host            $host:$server_port;
        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;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
server {
    access_log  logs/access.log;
    error_log   logs/error.log;
    index       index.html;
    root        /usr/local/nginx/html;
    server_name d**o*e**n.g***.net;
    listen 8100 ssl;
    ssl on;
    ssl_certificate      ssl1.cer;
    ssl_certificate_key  ssl1.key;

    ## Only allow these request methods
    if ($request_method !~ ^(GET|HEAD|POST)$ ) {
        return 444;
    }
 
    ## PROXY - Web
    location / {
        proxy_pass  https://gwapp;
        proxy_ignore_headers   Expires Cache-Control;
 
        proxy_set_header        Host            $host:$server_port;
        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;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

-----本人server示例 结束-----


另附nginx常用命令

1)下载地址:
  http://nginx.org
2)启动
  解压至c:\nginx,运行nginx.exe(即nginx -c conf\nginx.conf),默认使用80端口,日志见文件夹C:\nginx\logs
3)使用
  http://localhost
4)关闭
  nginx -s stop 或taskkill /F /IM nginx.exe > nul
5)常用配置
   C:\nginx\conf\nginx.conf,使用自己定义的conf文件如my.conf,命令为nginx -c conf\my.conf
6)查看nginx进程
  tasklist /fi "imagename eq nginx.exe",如下显示:
7)nginx常用命令
nginx -s stop 强制关闭
nginx -s quit 安全关闭
nginx -t 检测配置文件的正确性
nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效
nginx -s reopen 打开日志文件

你可能感兴趣的:(nginx)