-
前情:不是在本地,在服务器中。
-
问题:nginx 反向代理不生效。
- docker 启动容器命令
docker run --detach --name solo --network=host \
--env RUNTIME_DB="MYSQL" \
--env JDBC_USERNAME="root" \
--env JDBC_PASSWORD="root" \
--env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" \
--env JDBC_URL="jdbc:mysql://172.17.0.2:3307/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" \
b3log/solo --listen_port=8080 --server_scheme=http --server_host=
- 这是容器状态
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db1e11e36736 b3log/solo "java -cp WEB-INF/li…" 47 hours ago Up 9 minutes solo
6caf6540591d mysql:5.7 "docker-entrypoint.s…" 8 days ago Up 2 days 3306/tcp, 33060/tcp, 0.0.0.0:3307->3307/tcp mysql
- nginx 配置文件
因为没有域名,所以 server_name 使用 ip
server {
listen 80;
server_name 106.13.196.138;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 测试服务器中是否可以访问 127.0.0.1:8080
- 在服务器中可以访问到页面 html
[root@instance-qgtp1aez]~# curl http://127.0.0.1:8080
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet"alhost:8080/">on">lication/rss+xml" rel="alternate"/>nsearch.xml">
href="http://localhost:8080/scss/start.css?1568862416167" charset="utf-8"/>
<meta name="robots" content="none"/>
</head>
<body>
<div class="wrap">
<div class="content-wrap">
<div class="content">
<div class="main">
<h2>
<span>欢迎使用</span>
<a target="_blank" href="https://solo.b3log.org">
<span class="error"> Solo</span>
</a>
</h2>
<div id="github">
<div class="github__icon startAction">
<img src="http://localhost:8080/images/github.png"/>
</div>
<br>
<button class="startAction">登录 GitHub 账号后即可开始使用</button><br>
<a class="github__link" href="javascript:$('ul').slideToggle()">查看 GitHub 数据使用说明</a>
<div class="github__text">
<ul>
<li>获取用户名、头像等用于初始化</li>
<li>获取公开仓库信息用于展示</li>
<li>不会对你的已有数据进行写入</li>
</ul>
</div>
<label class="github__check">
<input type="checkbox" id="isAgreenCheck" checked>
<span>
是否愿意在 GitHub 上收藏该<a href="https://github.com/b3log/solo" target="_blank">项目</a>、关注<a href="https://github.com/88250" target="_blank">开发者</a>并加入 <a href="https://github.com/b3log" target="_blank">B3log 开源组织</a>
</span>
</label>
</div>
<script type="text/javascript" src="http://localhost:8080/js/lib/jquery/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript">
(function () {
try {
$('.startAction').click(function () {
var isAgreen = $('#isAgreenCheck').prop('checked') ? '0' : '1'
window.location.href = 'http://localhost:8080/oauth/github/redirect?referer=http%3A%2F%2Flocalhost%3A8080__' + isAgreen
$('#github').addClass('github--loading')
})
} catch (e) {
document.querySelector('.main').innerHTML = "<h2><a href='https://hacpai.com/tag/Latke' target='_blank'>Latke</a> 配置错误</h2><div style='text-align:center'><br><br><br>请浏览 <a target='_blank' href='https://hacpai.com/article/1474087427032'>Latke 配置剖析</a> 以解决该问题。<br><br><br></div>"
}
})()
</script>
</div>
</div>
</div>
<div class="footerWrapper">
<div class="footer">
Powered by <a href="https://b3log.org" target="_blank">B3log 开源</a> • <a href="https://solo.b3log.org" target="_blank">Solo</a> 3.6.4
</div>
</div>
</div>
</body>
</html>
<!-- Generated by Latke (https://github.com/b3log/latke) in 36ms, 2019/09/19 11:24:46 -->#
- tcp 端口
[root@instance-qgtp1aez]~# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2032/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1533/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5546/nginx: worker
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 8798/pure-ftpd (SER
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 8242/sshd
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 3186/python
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 15885/master
tcp6 0 0 :::3307 :::* LISTEN 15012/docker-proxy
tcp6 0 0 :::781 :::* LISTEN 2260/./bcm-agent
tcp6 0 0 :::111 :::* LISTEN 1533/rpcbind
tcp6 0 0 :::8080 :::* LISTEN 1733/java
tcp6 0 0 :::21 :::* LISTEN 8798/pure-ftpd (SER
tcp6 0 0 :::22 :::* LISTEN 8242/sshd
tcp6 0 0 ::1:25 :::* LISTEN 15885/master
- 最终定位可能是 nginx 反向代理没有生效,对 nginx 不太熟悉,求助热心网友帮助。多谢!