我有一个快速search(大约30分钟),并尝试了一些,但似乎没有任何工作。 另外请注意,我不是Linux专家(我可以做最基本的东西,简单的安装,configuration等),所以我有一些configuration可能显然是错的,但我只是没有看到它! (随时纠正下面的任何configuration)
安装程序
我在红帽企业Linux服务器版本7.1(Maipo)框上有一个正在运行的Postgresql 9.3实例。 它也在运行SELinux和IPTables。
IPTablesconfiguration(添加在80,443和5432 ..也是22,但是之前完成了…)
# sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
Postgresql pg_hba.cong(删除所有评论)
# TYPE DATABASE USER ADDRESS METHOD local all all ident host all all 127.0.0.1/32 md5 host all all ::1/128 md5 host all all 0.0.0.0/0 md5
postgresql.conf(只更改了监听地址)
listen_addresses = '*'
设置新用户
$ sudo -u postgres /usr/pgsql-9.3/bin/createuser -s "pgadmin" $ sudo -u postgres /usr/pgsql-9.3/bin/createuser "webuser" $ sudo -u postgres psql postgres=# ALTER ROLE "pgadmin" WITH PASSWORD 'weakpassword'; ALTER ROLE postgres=# ALTER ROLE "webuser" WITH PASSWORD 'anotherweakpassword'; ALTER ROLE postgres=# q
testing连接
psql -U [pgadmin|webuser] -h [localhost|127.0.0.1|hostname] -W postgres Password for user [pgadmin|webuser]: [weakpassword|anotherweakpassword] psql (9.3.7) Type "help" for help. postgres=# q
正如你所看到的,我在命令行testing了127.0.0.1,localhost和主机名,以确保我可以连接使用所有三个标识符与两个不同的帐户。
我也使用PgAdmin从我的Windows中连接,并使用两个用户的主机名和IP地址进行连接。
XAMPP在Windows 7启动时自动启动
将非www和非httpsredirect到https:// www
使用mod_wsgi在Apache上部署django应用程序
Apache RewriteEngine On导致403错误
RewriteRule不能在.htaccess中写入Windows(Apache)
问题…
当我尝试从PHP通过Apache连接时出现问题(如果我在命令行上运行相同的脚本,则不会发生这种情况)
PHPtesting脚本
<?PHP error_reporting( E_ALL ); ini_set('display_errors','1'); $conn1 = pg_connect("host='localhost' port='5432' user='pgadmin' password='weakpassword' dbname='postgres'"); $conn2 = pg_connect("host='127.0.0.1' port='5432' user='pgadmin' password='weakpassword' dbname='postgres'"); $conn3 = pg_connect("host='localhost' port='5432' user='webuser' password='anotherweakpassword' dbname='postgres'"); $conn4 = pg_connect("host='127.0.0.1' port='5432' user='webuser' password='anotherweakpassword' dbname='postgres'"); $status1 = pg_connection_status( $conn1 ); $status2 = pg_connection_status( $conn2 ); $status3 = pg_connection_status( $conn3 ); $status4 = pg_connection_status( $conn4 ); # Check connection if ( $status1 === false || $status1 === PGsql_CONNECTION_BAD || $status2 === false || $status2 === PGsql_CONNECTION_BAD || $status3 === false || $status3 === PGsql_CONNECTION_BAD || $status4 === false || $status4 === PGsql_CONNECTION_BAD ) { throw new Exception("I'm broken"); } # Do a query $res1 = pg_query( $conn1,"SELECT * FROM pg_type LIMIT 1" ); $res2 = pg_query( $conn2,"SELECT * FROM pg_type LIMIT 1" ); $res3 = pg_query( $conn3,"SELECT * FROM pg_type LIMIT 1" ); $res4 = pg_query( $conn4,"SELECT * FROM pg_type LIMIT 1" ); # Test one result. $row1 = pg_fetch_row($res1); $row2 = pg_fetch_row($res2); $row3 = pg_fetch_row($res3); $row4 = pg_fetch_row($res4); echo $row1[0] . "n"; echo $row2[0] . "n"; echo $row3[0] . "n"; echo $row4[0] . "n";
在命令行我得到以下输出(如预期)
bool bool bool bool
但在浏览器中,我得到以下
Warning: pg_connect(): Unable to connect to Postgresql server: Could not connect to server: Permission denied Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? Could not connect to server: Permission denied Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? in /var/www/html/test.PHP on line 6 Warning: pg_connect(): Unable to connect to Postgresql server: Could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? in /var/www/html/test.PHP on line 7 Warning: pg_connect(): Unable to connect to Postgresql server: Could not connect to server: Permission denied Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? Could not connect to server: Permission denied Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? in /var/www/html/test.PHP on line 8 Warning: pg_connect(): Unable to connect to Postgresql server: Could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? in /var/www/html/test.PHP on line 9 Fatal error: Uncaught exception 'Exception' with message 'I'm broken' in /var/www/html/test.PHP:25 Stack trace: #0 {main} thrown in /var/www/html/test.PHP on line 25
我有一种感觉,这是IPTables不能允许通过Apache通过某种原因通过连接,但我很难(我敢打赌,这是愚蠢的简单)
我认为这涵盖了一切
帮助我堆栈溢出,你是我唯一的希望!
Apache .htaccess <目录不允许在这里
使用htaccess从URL中删除字符
HttpServletRequest对象的远程IP地址被Apache Proxy遮挡
如何在AppFog中使用Apache的静态内容(Wsgi Python应用程序)
使用Apache POI创buildExcel图表
OK …回答…是SELinux的问题。 需要运行以下….
setsebool -P httpd_can_network_connect_db on
此外,如果您需要检查SELinux是否导致问题,可以通过以下方法关闭SELinux
setenforce 0
然后一旦完成
setenforce 1
无论如何,做…起点!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。