首页 > 系统相关 >『中级篇』docker之运行nginx跳转到本地的jar并配置https(番外篇)(80)

『中级篇』docker之运行nginx跳转到本地的jar并配置https(番外篇)(80)

时间:2023-01-06 11:33:56浏览次数:41  
标签:http log conf jar nginx proxy https 跳转 docker

2g内存,安装了mysql容器,java容器,nginx容器。具体安装docker我就不说了,没啥讲的重复很多遍的。mysql 也之前讲过。

nginx的安装

  • 新建立nginx的目录
nginx
  • 防止出现下面的错误
docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused "rootfs_linux.go:57: mounting \"/root/conf/nginx/nginx.conf\" to rootfs 
\"/var/lib/docker/aufs/mnt/edd3b9a8923f13404d42aa73f509b625c7370791c8
25424427eacae6432fecc8\" at \"/var/lib/docker/aufs/mnt/edd3b9a8923f13404d42aa73f509b625c7370791c8
25424427eacae6432fecc8/etc/nginx/nginx.conf\" caused \"not a directo
![](/i/li/?n=2&i=images/blog/202301/06111642_63b7929a307c613078.png?,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)ry\"""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
  • 命令建立

确定文件夹存在

touch conf/nginx.conf
echo 1 > conf/nginx.conf

创建容器

docker run -d -p 80:80 \
--name five-nginx \
-p 443:443 \
-v /home/user/nginx/cert:/etc/nginx/cert \
-v /home/user/nginx/config/nginx.conf:/etc/nginx/nginx.conf \
-v /home/user/nginx/html:/usr/share/nginx/html \
-v /home/user/nginx/log:/var/log/nginx \
hub.c.163.com/library/nginx
  • 配置nginx文件

『中级篇』docker之运行nginx跳转到本地的jar并配置https(番外篇)(80)_nginx

#user  nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}


http {
include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;
server {
listen 80;
server_name www.abc.xyz;
rewrite ^ https://$http_host$request_uri? permanent;
}
server {
listen 443;
server_name www.abc.xyz;
ssl on;
ssl_certificate /etc/nginx/cert/www.idig8.xyz.crt;
ssl_certificate_key /etc/nginx/cert/www.idig8.xyz.key;
ssl_session_timeout 5m;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://172.17.0.3:8888/;
proxy_redirect off;
}
}
}
  • java项目启动使用的是8888端口

nginx的配置 proxy_pass 不能使用127.0.0.1:8888
必须使用java容器内部的ip地址http://172.17.0.3:8888/; 可以通过docker inspect 来进行查看。

  • https的配置

『中级篇』docker之运行nginx跳转到本地的jar并配置https(番外篇)(80)_nginx_02

把cert阿里云中下载的crt,key放入指定的目录cert中。

PS:基本的nginx容器配置秘钥和key,跳转返回的时候,访问java容器的IP。

标签:http,log,conf,jar,nginx,proxy,https,跳转,docker
From: https://blog.51cto.com/u_12040702/5992895

相关文章

  • java -jar 指定logback.xml、application.yaml
    java-jar指定logback.xml -Dlogging.config="C:\logbacs\logback.xml"示例:java-jar  -Dlogging.config="/home/yqq/config/logback.xml" zwdatagather-1.0.0......
  • 加解密与HTTPS(5)
    您好,我是湘王,这是我的51CTO博客,欢迎您来,欢迎您再来~咱们大学读完之后有毕业证书,并且这个证书可以在学信网查询。专业上有注会、CCIE、律师证等,可以在国家职业认证机构或委托......
  • Nginx根据用户IP设置访问跳转
    Nginx判断用户IP设置访问跳转第一种方法根据$remote_addr客户端IP地址判断,判断成功即返回301跳转,可以写正则,如果有大量不规则IP就很头疼了。23if($remote_addr=192......
  • 使用IDEA打包项目(jar包和war包) pom.xml
      介绍jar包假设将整个项目视为一堵墙,那么jar包就是砖块,将写好的类进行打包的过程就是烧制砖块的过程。jar包是class文件和部署文件的归档,不包含静态文件,它不仅用于......
  • 2.树莓派使用frp内网穿透http,https
    原材料准备(在服务端和客户端均执行一次)下载压缩包wgethttps://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz执行以下命令,解压f......
  • manjaro/Linux设置开机启动脚本
     /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置 /etc/rc.d/rc.local在这......
  • Vue3路由的redirect重定向结合函数实现不同的用户身份跳转到不同的首页
    访问网页主域名的时候,识别用户身份跳转到不同的首页,配置路由重定向constroutes:Array<RouteRecordRaw>=[//访问主域名的时候,根据用户的登录信息,重定向到不同的页......
  • Unity跳转场景报空指针解决
    当跳转场景时,有时候会出现空指针问题。解决办法:将即将跳转到的scene添加到BuildSettings里面。举个例子:例如从某个场景要跳转到network这个场景中,那么BuildSettings里面必......
  • springboot项目启动报错Command line is too long. Shorten the command line via JAR
      报错原因:springboot项目启动命令过长 方案一:修改配置点击项目启动配置项-->Enviroment-->Shortencommandline选项-->选择classpathfile或JARmanifes......
  • HTTPS和HTTP的区别
    以前登录时候向服务器传递的是明文username:张三password:123456到了后台将123456密码用MD5加密后保存到数据库。现在就有了个问题,传输过程中是明文传输的,不安全。如何将......