`

nginx配置

阅读更多

 nginx tomcat ssl

一、生成证书(如已有证书,可略过)

1. 通过keytool 生成密钥库 【注意 CN 为服务端访问域名地址或者IP地址或者主机名 比如 config.ebnew.com】(密钥库密码 为:bidconfig)

keytool-genkey-aliasconfigserver-keystoreconfigstore.jks-keypassbidconfig-storepassbidconfig-keyalgRSA -validity 7300 -v -dname "CN =config.ebnew.com,O = BID,DC = Server Https,DC = BID,OU = Firefly Technology And Operation"

2. 通过keytool将密钥库导出为P12 (密钥库密码为:bidconfig, p12 密钥库密码为:bidconfig)

keytool -importkeystore -srckeystore configstore.jks -destkeystore config.p12 -srcstoretype JKS -deststoretype PKCS12 - srcstorepass bidconfig -deststorepass bidconfig -srcalias configserver -destalias configserver -srckeypass bidconfig - destkeypass bidconfig -noprompt

3.根据pkcs12 (config.p12) 生成证书请求 config.pem (密码都为 bidconfig. 根据自己需要定义out密码) openssl pkcs12 -in config.p12 -out config.pem -passin pass:bidconfig -passout pass:bidconfig

4. 根据p12 密钥库分别导出 服务端私钥,与服务端证书以及客服端证书(双向认证时使用)。 openssl pkcs12 -in config.p12 -nodes -nocerts -out server.key
openssl pkcs12 -in config.p12 -nodes -nokeys -clcerts -out server.crt
openssl pkcs12 -in config.p12 -nodes -nokeys -cacerts -out client.crt

5.通过keytool 将服务端证书导入到客服端(java) 密钥库。密钥库密码设置为 liu999,方便java客服端使用 keytool -import -alias configTrustServer -file server.crt -keystore configclient.jks -storepass liu999

6. 如果是浏览器访问跳过安全检查
keytool -import -file ./server.crt -keystore "%JAVA_HOME%\jre\lib\security\cacerts" -alias config -trustcacerts

二、 nginx (192.168.0.182在这个主机上安装nginx)

1.安装
安装文件nginx-1.8.0.tar.gz

解压到 /home/ci/nginx-1.8.0

yum -y install pcre-devel
yum -y install make gcc gcc-c++ ncurses-devel yum -y install zlib zlib-devel
yum -y install openssl openssl-devel

安装目录:/home/ci/nginx
./configure --prefix=/home/ci/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

make

make install

查看文件是否正确
sudo /home/ci/nginx/sbin/nginx -t 启动服务
sudo /home/ci/nginx/sbin/nginx
停止服务
sudo /home/ci/nginx/sbin/nginx -s stop sudo pkill -9 nginx
加载配置文件
sudo /home/ci/nginx/sbin/nginx -s reload 查看进程
ps -ef|grep nginx

2. 修改配置 /home/ci/nginx/conf/nginx.conf

http {
include mime.types;
default_type application/octet-stream;

sendfile on; keepalive_timeout 65;

server {
listen 80;
server_name localhost;
rewrite^(.*)$https://$host$1permanent; //自动将http请求,转到https

#location / {
#root html;
#index index.html index.htm;
#proxy_pass
http://192.168.0.182:7080/maven-web-demo/;

#}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html #
error_page 500502503504 /50x.html;
location = /50x.html {

root html; }

}

# HTTPS server #
server {

listen 443 ssl; server_name localhost;

ssl_certificate /home/ci/server.crt; 证书 ssl_certificate_key /home/ci/server.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;
proxy_pass
http://192.168.0.182:7080/maven-web-demo/;

} }

9. tomcat 配置
<Connector port="7080" protocol="HTTP/1.1"

connectionTimeout="20000" redirectPort="8443" proxyPort="443"/>

三、测试 浏览器访问地址 http://192.168.0.182 https://192.168.0.182

四、生产环境 若是生产环境注意域名解析后指定的机器映射配置

[~]$ sudo yum -y install pcre-devel
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist
http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was 14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base

如果配置的DHCP动态网络,则在/etc/resolv.conf文件中添加 nameserver 8.8.8.8

参考网址:
NGINX配置HTTPS加密访问–自签CA » 月飞博客 (生成证书)

Nginx开发从入门到精通 — Nginx开发从入门到精通 (最全的,可以当本书来看)
nginx + tomcat + java SSL客服端 - 市井之思维,不适于高远之欲。 - 开源中国社区

Linux+Nginx/Apache/Tomcat新增SSL证书,开启https访问教程 | 张戈博客

ngx_http_ssl_module Nginx配置文件nginx.conf中文详解 - - ITeye技术网站
转载:nginx proxy_pass 里的”/” - 那年那月 - 博客园
(重点,必看)

Nginx学习笔记 - mcj8089 - ITeye技术网站 (可看)

Nginx多Server反向代理配置 - 51CTO.COM

专题:Nginx安装配置与服务搭建_51CTO.COM

 

分享到:
评论

相关推荐

    Nginx 配置文件 nginx.conf 详解

    Nginx 配置文件 nginx.conf 详解 Nginx 配置文件 nginx.conf 是 Nginx 服务器的核心配置文件,它控制着 Nginx 服务器的行为和性能。在这个配置文件中,我们可以设置服务器的用户和组、工作进程数、错误日志、进程...

    windows下 php+nginx配置详解

    设置监听地址和端口,与Nginx配置中的`fastcgi_pass`对应: ```ini listen = 127.0.0.1:9000 ``` 启动Nginx和PHP-FPM服务。如果一切配置无误,现在你应该可以通过浏览器访问`http://localhost/`并看到Nginz的欢迎...

    nginx配置 +负载均衡+https协议

    - 对于负载均衡,可以通过在Nginx配置文件中定义多个后端服务器,并使用`proxy_pass`指令来实现。 ```nginx upstream backend { server backend1.example.com; server backend2.example.com; } server { ...

    notepad++编辑nginx配置文件支持高亮

    在标题“notepad++编辑nginx配置文件支持高亮”中,我们关注的是如何在Notepad++中实现对Nginx配置文件的语法高亮显示,这将极大提升开发者的阅读和编写效率。 Nginx是一款高性能的HTTP和反向代理服务器,其配置...

    微信小程序https服务nginx配置示例.pdf

    6. 反向代理配置:在nginx配置中,proxy_pass指令用于指定后端的服务器地址,这里指向了本地的8080端口。同时,还通过proxy_set_header指令设置了传递给后端服务器的HTTP头信息,如X-Forwarded-For(客户端IP地址)...

    Windows平台,Nginx配置文件修改自动加载重启

    本教程将介绍一种方法,使得在Windows环境下,Nginx配置文件修改后能够自动加载并重启,以实现配置的即时生效。 首先,`nginx.conf`是Nginx的主要配置文件,它包含了服务器的各项设置,如监听端口、服务器块、反向...

    Nginx配置SSL自签名证书的方法

    3. **编辑Nginx配置文件**:找到Nginx的配置文件,通常是`/etc/nginx/nginx.conf`或`/usr/local/nginx/conf/nginx.conf`。添加一个新的`server`块,配置如下: ```nginx server { listen 80; listen 443 ssl; # ...

    项目打包运行dist以及nginx配置

    在IT行业中,项目打包运行和Nginx配置是两个关键环节,它们对于应用程序的部署和发布至关重要。这里我们将深入探讨这两个主题。 首先,项目打包运行通常指的是将开发完成的前端或后端应用转换为可部署的形式。对于...

    Vue项目部署Nginx配置文件 SSL

    在部署 Vue 项目时,Nginx 配置文件 `nginx.conf` 的关键设置如下: 1. **基本配置**: - `server` 块:定义一个监听特定端口(通常是80)的服务器实例。 ```nginx server { listen 80; server_name your...

    windows下nginx配置https以及同一个端口监听多个网站即监听多个虚拟主机

    在Windows环境下,配置Nginx以支持HTTPS及在同一端口监听多个网站,即配置多个虚拟主机,是一项常见的网络服务设置任务。...同时,根据实际需求,还可以对Nginx配置进行更复杂的优化,如负载均衡、缓存等。

    Nginx配置如何区分PC或手机访问不同域名

    在Nginx配置中,我们通常使用`if`语句和`rewrite`模块来根据不同的条件重写请求。例如,若想在移动端访问时重定向到另一个域名(如***),可以利用Nginx配置文件中的`if`语句,结合正则表达式匹配HTTP_USER_AGENT,...

    Nginx配置http转https以及https访问http静态资源.docx

    三、Nginx配置安全头 在上面的配置文件中,我们使用了add_header指令来添加Content-Security-Policy头,以便升级不安全的请求。这可以防止攻击者inject恶意脚本来攻击网站。 四、Nginx配置错误页面 在上面的配置...

    nginx配置.zip

    1. **Nginx配置基础** Nginx的配置文件通常位于`/etc/nginx/`目录下,其中`nginx.conf`是主配置文件,它包含了整个Nginx服务器的基本设置。`conf.d`目录则用于存放多个独立的配置片段,这种方式使得配置管理更加...

    Nginx配置多个访问路径

    Nginx配置多个service 多个访问路径 找到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 ...

    squid和nginx配置正向代理访问API接口.rar

    总结一下,"squid和nginx配置正向代理访问API接口"涉及的关键知识点包括正向代理的概念、Squid和Nginx的代理功能、配置这两者的步骤、以及安全性控制和优化策略。正确配置和使用这两个工具可以帮助企业构建高效、...

    Nginx配置文件——一级域名、二级域名

    本文将深入探讨如何通过Nginx配置文件来设置一级域名和二级域名,以及如何利用Nginx的反向代理功能。 首先,了解一级域名和二级域名的概念至关重要。一级域名是互联网上顶级的域名,如.com、.org、.net等。二级域名...

    nginx配置文件.zip

    在本例中,Nginx配置文件可能是为了在Docker容器内优化网络服务性能和资源利用率。 4. **配置文件详解**:Nginx的配置文件通常以`.conf`为扩展名,包含一系列指令和块。`http`、`server`和`location`是最基本的配置...

Global site tag (gtag.js) - Google Analytics