該賞金過期5天。此問題的答案有資格獲得 200聲望獎勵。 Jamie Hutber想引起對這個問題的更多關注:
可悲的是,我仍然沒有更接近這一點!我認為/相信我的 apache 端的一切設定都正確,在提交時幾乎嘗試了每一個 SO QA,但它們似乎都沒有奏效。
我正在嘗試讓一個全新的基于云的服務器與默認版本的 20.04 服務器 ubuntu 一起作業,該服務器與 apache 和 node 一起作業。節點服務器似乎正在運行,沒有報告 4006 埠已打開的問題。但是我相信我的 apache 配置不是。該請求將掛起很長時間。節點終端中不顯示任何錯誤。因此,錯誤必須出在我的 apache 配置中,因為我們收到了以下 apache 錯誤并且沒有 JS 錯誤。
一段時間后請求錯誤
502 proxy error
Apache 錯誤日志
[Sun Oct 17 20:58:56.608793 2021] [proxy:error] [pid 1596878] (111)Connection refused: AH00957: HTTP: attempt to connect to [::1]:4006 (localhost) failed
[Sun Oct 17 20:58:56.608909 2021] [proxy_http:error] [pid 1596878] [client 207.46.13.93:27392] AH01114: HTTP: failed to make connection to backend: localhost
虛擬主機
<VirtualHost IP_ADDRESS:80>
ServerName api.aDomain.com
Redirect permanent / https://api.aDomain.com/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost IP_ADDRESS:443>
ServerName api.aDomain.com
ProxyRequests on
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
ProxyPass / http://localhost:4006/
ProxyPassReverse / http://localhost:4006/
#certificates SSL
SSLEngine on
SSLCACertificateFile /etc/ssl/api.aDomain.com/apimini.ca
SSLCertificateFile /etc/ssl/api.aDomain.com/apimini.crt
SSLCertificateKeyFile /etc/ssl/api.aDomain.com/apimini.key
ErrorLog ${APACHE_LOG_DIR}/error_api.aDomain.com.log
CustomLog ${APACHE_LOG_DIR}/access_api.aDomain.com.log combined
</VirtualHost>
</IfModule>
終端輸出
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node -r dotenv/config --inspect=9229 index.js`
Debugger listening on ws://127.0.0.1:9229/c1fcf271-aea8-47ff-910e-fe5a91fce6d2
For help, see: https://nodejs.org/en/docs/inspector
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
?? Server ready at http://localhost:4006
節點服務器
import cors from 'cors'
import scrape from './src/api/routes/scrape'
const express = require('express')
const { ApolloServer, gql } = require('apollo-server-express')
const { postgraphile } = require('postgraphile')
const ConnectionFilterPlugin = require('postgraphile-plugin-connection-filter')
const dbHost = process.env.DB_HOST
const dbPort = process.env.DB_PORT
const dbName = process.env.DB_NAME
const dbUser = process.env.DB_USER
const dbPwd = process.env.DB_PWD
const dbUrl = dbPwd
? `postgres://${dbUser}:${dbPwd}@${dbHost}:${dbPort}/${dbName}`
: `postgres://${dbHost}:${dbPort}/${dbName}`
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
}
async function main() {
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
}
const server = new ApolloServer({ typeDefs, resolvers })
const app = express()
app.use(cors(corsOptions))
app.use(
postgraphile(process.env.DATABASE_URL || dbUrl, 'public', {
appendPlugins: [ConnectionFilterPlugin],
watchPg: true,
graphiql: true,
enhanceGraphiql: true,
})
)
server.applyMiddleware({ app })
//Scraping Tools
scrape(app)
const port = 4006
await app.listen({ port })
console.log(`?? Server ready at http://localhost:${port}`)
}
main().catch(e => {
console.error(e)
process.exit(1)
})
Apache Mods 已啟用
/etc/apache2/mods-enabled/proxy.conf /etc/apache2/mods-enabled/proxy.load /etc/apache2/mods-enabled/proxy_http.load
更新的錯誤日志
[Thu Oct 21 10:59:22.560608 2021] [proxy_http:error] [pid 10273] (70007)The timeout specified has expired: [client 93.115.195.232:8963] AH01102: error reading status line from remote server 127.0.0.1:4006, referer: https://miniatureawards.com/
[Thu Oct 21 10:59:22.560691 2021] [proxy:error] [pid 10273] [client 93.115.195.232:8963] AH00898: Error reading from remote server returned by /graphql, referer: https://miniatureawards.com/
uj5u.com熱心網友回復:
我不是這個主題的專家,但我有類似的設定;我socket.io用來服務 WebSockets ...
從您的帖子看來,您似乎也不需要代理 WebSockets,日志中顯示的似乎僅用于除錯目的(如果我錯了,請糾正我)。
遵循我的 Apache 配置的核心:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:4006/$1 [P,L]
<Location />
ProxyPass http://127.0.0.1:4006/ retry=2
ProxyPassReverse http://127.0.0.1:4006/
</Location>
另外幾個建議。
警告
ProxyRequests在保護服務器之前不要啟用代理。開放代理服務器對您的網路和整個 Internet 都是危險的。
來源:https : //httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxyrequests
我不知道您主機上的 IPV6 設定是什么,您可以嘗試使用127.0.0.1而不是localhost在您的 Apache 配置中嘗試強制 Apache 使用 IPV4。
uj5u.com熱心網友回復:
如果您為節點服務器使用 docker,則它可能設定不正確
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/329461.html
標籤:javascript 节点.js 阿帕奇 ssl 反向代理
