AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-461150

peter's questions

Martin Hope
peter
Asked: 2022-11-17 06:04:14 +0800 CST

为什么apache httpd.conf中SetEnv设置的环境变量不能传递给php?

  • 6

我在 httpd.conf 中设置了一个环境变量:

SetEnv http_proxy "http://localhost:3128"

但是我无法使用以下方法在 php 中获取此变量getenv:

<?php
echo getenv("http_proxy");
phpinfo();
print_r($_ENV);

getenv返回空并print_r($_ENV)显示以下内容:

Array ( [LANG] => C [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin [NOTIFY_SOCKET] => /run/systemd/notify ) 

有趣的是,环境变量显示在phpinfo输出的“Apache 环境”部分下。

(我的系统是apache 2.4/php 5.6/CentOS7)

apache-2.2
  • 1 个回答
  • 98 Views
Martin Hope
peter
Asked: 2022-11-16 09:11:55 +0800 CST

如何在 CentOS 上为 php file_get_contents 配置系统范围的代理?

  • 5

我想让 php file_get_content 函数通过系统范围的代理连接到网络。我尝试在 /etc/environment 中添加以下行:

http_proxy=http://localhost:3128/
HTTP_PROXY=http://localhost:3128/
https_proxy=http://localhost:3128/
HTTPS_PROXY=http://localhost:3128/

但它不适用于 file_get_content,尽管它适用于 wget。我还尝试将以下行添加到 /etc/profile:

PROXY_URL="http://localhost:3128/"

export http_proxy="$PROXY_URL"
export https_proxy="$PROXY_URL"
export ftp_proxy="$PROXY_URL"

# For curl
export HTTP_PROXY="$PROXY_URL"
export HTTPS_PROXY="$PROXY_URL"
export FTP_PROXY="$PROXY_URL"

同样,它不起作用。我创建了以下 test.php:

<?php
$aContext = array(
    'http' => array(
        'proxy'           => 'tcp://localhost:3128',
        'request_fulluri' => true,
    ),
);
$cxContext = stream_context_create($aContext);

$sFile = file_get_contents("https://www.google.com", False, $cxContext);

echo $sFile;

这个脚本确实有效。但是由于我无法修改所有包含 file_get_contents 的源代码,所以我需要一个系统范围的代理。我该怎么做?

centos
  • 1 个回答
  • 54 Views
Martin Hope
peter
Asked: 2022-11-14 07:11:50 +0800 CST

如何找到发出出站连接的 php 脚本?

  • 5

我有一个为多个网站运行 httpd 的服务器。使用 top 命令,我发现许多 httpd 进程耗尽内存。使用 netstat 命令,我发现 httpd 进程正在连接到外部 ip 地址。是否可以找到发出连接的 (php) 脚本/函数?

php
  • 1 个回答
  • 45 Views
Martin Hope
peter
Asked: 2022-11-14 06:01:53 +0800 CST

如何查看出站连接的 httpd 日志?

  • 9

在 httpd.conf 中为网站指定的访问日志仅显示传入连接的信息。对于出站连接,比如php file_get_contents函数发出的连接,如何获取log?

apache-2.2
  • 4 个回答
  • 942 Views
Martin Hope
peter
Asked: 2021-12-02 07:45:03 +0800 CST

为什么 .htaccess 中的重定向不起作用?

  • 2

我有一个 Wordpress 网站。我想将 .php 网址重定向到没有 .php 后缀的网址。.htaccess 如下:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On


RewriteRule ^(.*)\.php$ "$1" [R=301,L,NC]


RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

但是当我访问https://www.example.com/somepage.php时,页面无法显示。浏览器中显示以下错误:

The page isn’t redirecting properly

    An error occurred during a connection to www.example.com.
    
        This problem can sometimes be caused by disabling or refusing to accept cookies.

地址栏中的 url 变为 https://www.example.com/index。

如果我将重写规则更改为:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On


RewriteRule ^(.*)\.html$ "$1" [R=301,L,NC]


RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

并访问https://www.example.com/somepage.html,成功重定向到https://www.example.com/somepage,网页正常显示。为什么?

.htaccess
  • 0 个回答
  • 282 Views
Martin Hope
peter
Asked: 2021-11-29 07:41:47 +0800 CST

所有数据库的一个用户还是不同数据库的不同用户?

  • 1

我有多个使用不同 mysql 数据库的(Wordpress)网站。我想知道是否应该对不同的数据库使用不同的用户,或者只对所有数据库使用一个用户(例如 root),只考虑性能而不考虑安全性。

mysql database database-performance
  • 1 个回答
  • 83 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve