我试图设置nginx的Docker容器,这是在同一个网络作为2 WordPress的网站容器。这是nginx.conf文件
worker_processes 512;
events {
worker_connections 1024;
}
http {
upstream informatica_site {
server InformaticaSite:80;
}
upstream informatica_blog {
server InformaticaBlog:80;
}
server {
listen 80;
server_name informaticasystems.xom;
location / {
proxy_pass http://informatica_site;
}
}
server {
listen 80;
server_name blog.informaticasystems.xom;
location / {
proxy_pass http://informatica_blog;
}
}
}
主机文件
127.0.0.1 informaticasystems.xom
127.0.0.1 blog.informaticasystems.xom
但当我组成了,JavaScript文件没有正确加载
他们试图访问proxy_pass而不是实际的服务器名称。
只是澄清一下,nginx和wordpress网站都在同一网络上的docker容器中,我在本地机器上从浏览器访问(在docker之外)
version: '3'
services:
InformaticaSite:
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: ******
WORDPRESS_DB_USER: ******
WORDPRESS_DB_PASSWORD: ******
WORDPRESS_DB_NAME: ******
volumes:
- ./informatica_site:/var/www/html
ports:
- "8081:80"
networks:
- informatica_network
InformaticaBlog:
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: ******
WORDPRESS_DB_USER: ******
WORDPRESS_DB_PASSWORD: ******
WORDPRESS_DB_NAME: ******
volumes:
- ./informatica_blog:/var/www/html
ports:
- "8082:80"
networks:
- informatica_network
informatica_site_db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: ******
MYSQL_DATABASE: ******
MYSQL_USER: ******
MYSQL_PASSWORD: ******
volumes:
- ./mysql_site_data:/var/lib/mysql
networks:
- informatica_network
informatica_blog_db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: ******
MYSQL_DATABASE: ******
MYSQL_USER: ******
MYSQL_PASSWORD: ******
volumes:
- ./mysql_blog_data:/var/lib/mysql
networks:
- informatica_network
nginx:
image: nginx
restart: always
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
networks:
- informatica_network
networks:
informatica_network:
根据我所能搜索的proxy_pass是不应该这样做的,我是nginx的新手,所以可能错过了一些东西。
1条答案
按热度按时间lh80um4z1#
你可以尝试使用以下
nginx.conf
:这样,nginx作为代理将最初请求的URL放在X-Forwarded-For头中。Wordpress读取它并根据该值创建链接。在wordpress得到nginx的请求之前,只有一个可以使用。现在你将原始请求的值(到nginx)传递给wordpress。