我有nginx设置为事实上的端口80 。 我想在Apache2上设置django + mod_wsgi。 我很担心,如果我离开Apache2为80会导致冲突。
避免头痛并将Apache更改为另一个端口更好吗?
server { listen 80; server_name work.domain.org; access_log /www/work.domain.org/log/access.log; error_log /www/work.domain.org/log/error.log; location / { proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Magic-Header "secret"; client_max_body_size 10m; } }
一般而言,您希望反向代理侦听要连接到的端口。 因此,在这种情况下,您希望nginx位于端口80上.Apache端口实际上并不重要,只要该端口在具有相同IP的同一台服务器上无法使用,就可能是端口80。
所以,如果您的反向代理机器也不运行Apache,那么它们都可能是80.您也可以在主机上拥有一个辅助IP,并将Apache绑定到该IP /端口对,同时让nginx和Apache在端口上侦听80在同一台机器上(只是不同的IP)。
例如(nc监听指定的IP和端口):
#Add Secondary IP: $ sudo ifconfig eth0:1 192.168.2.1 netmask 255.255.255.0 # Listen on primary IP: $ nc -l -p 20200 -s 192.168.1.2 #Listen on Secondary IP in another Terminal $ nc -l -p 20200 -s 192.168.2.1 Show in Yet another Terminal $ sudo netstat -tapnl | grep 20200 tcp 0 0 192.168.2.1:20200 0.0.0.0:* LISTEN 440/nc tcp 0 0 192.168.254.82:20200 0.0.0.0:* LISTEN 428/nc
想一下,我有种回答我自己的问题:
Starting web server: apache2(98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs failed! invoke-rc.d: initscript apache2, action "start" failed. Press return to continue.
无法绑定到相同的端口,因此我必须select另一个端口。 我可以发誓,虽然有人提到既设置为80端口,猜我误读。
您可以将它们绑定到相同的端口,但在不同的接口上。 例如,您可以将您的前端绑定到端口80上的外部IP,并将后端绑定到端口80上的本地主机。