- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我的 nginx 虚拟主机配置。
debian:~# cat /etc/nginx/sites-enabled/mybox
server {
listen 8080;
root /www;
index index.html index.htm;
server_name mybox;
location /foo {
uwsgi_pass unix:/tmp/uwsgi.sock;
include uwsgi_params;
uwsgi_param SCRIPT_NAME /foo;
uwsgi_modifier1 30;
}
}
这是我的 WSGI 应用程序的源代码。
debian:~# cat /www/app.py
def application(environ, start_response):
path_info = script_name = request_uri = None
if 'PATH_INFO' in environ:
path_info = environ['PATH_INFO']
if 'SCRIPT_NAME' in environ:
script_name = environ['SCRIPT_NAME']
if 'REQUEST_URI' in environ:
request_uri = environ['REQUEST_URI']
output = 'PATH_INFO: ' + repr(path_info) + '\n' + \
'SCRIPT_NAME: ' + repr(script_name) + '\n' + \
'REQUEST_URL: ' + repr(request_uri) + '\n'
start_response('200 OK', [('Content-Type','text/plain')])
return [output.encode()]
我使用这两个命令为我的 WSGI 应用程序提供服务:
service nginx restart
uwsgi -s /tmp/uwsgi.sock -w app --chown-socket=www-data:www-data
这是我尝试访问我的 Web 应用程序时看到的输出。
debian:~# curl http://mybox:8080/foo/bar
PATH_INFO: '/foo/bar'
SCRIPT_NAME: '/foo'
REQUEST_URL: '/foo/bar'
因为我在我的 nginx 虚拟主机配置中提到了 uwsgi_modifier1 30;
,所以我希望 PATH_INFO 只是 '/bar'
,如以下两个 URL 中所述:
引用第一篇文章相关部分:
The
uwsgi_modifier1 30
option sets the uWSGI modifierUWSGI_MODIFIER_MANAGE_PATH_INFO
. This per-request modifier instructs the uWSGI server to rewrite the PATH_INFO value removing the SCRIPT_NAME from it.
引用第二篇文章的相关部分:
Standard WSGI request followed by the HTTP request body. The PATH_INFO is automatically modified, removing the SCRIPT_NAME from it.
但我看到我的 PATH_INFO 保持不变,如 '/foo/bar'
。 SCRIPT_NAME 部分,即 '/foo'
尚未从中删除。为什么?
最佳答案
看完https://github.com/unbit/uwsgi/pull/19我知道不推荐使用 uwsgi_modifier1 30;
。
这就是我解决问题的方法。
首先,我通过删除以下两行删除了 nginx 中的 SCRIPT_NAME 处理:
uwsgi_param SCRIPT_NAME /foo;
uwsgi_modifier1 30;
生成的 nginx 配置如下所示:
debian:~# cat /etc/nginx/sites-enabled/mybox
server {
listen 8080;
root /www;
index index.html index.htm;
server_name mybox;
location /foo {
uwsgi_pass unix:/tmp/uwsgi.sock;
include uwsgi_params;
}
}
然后我重新启动了 nginx,并使用 --mount
和 --manage-script-name
选项在 uwsgi 中处理了 SCRIPT_NAME,就像这样。
service nginx restart
uwsgi -s /tmp/uwsgi.sock -w app --chown-socket=www-data:www-data --manage-script-name --mount=/foo=/www/app.py
现在,我得到了预期的输出。
debian:~# curl http://mybox:8080/foo/bar
PATH_INFO: '/bar'
SCRIPT_NAME: '/foo'
REQUEST_URL: '/foo/bar'
关于python - `uwsgi_modifier1 30` 指令没有按照记录从 PATH_INFO 中删除 SCRIPT_NAME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22642124/
我有许多 django 应用程序在同一域中运行,但在让 SCRIPT_NAME 与 Gunicorn 正常工作时遇到问题。 示例应用程序路径: www.domain.com/app1 www.doma
我有许多 django 应用程序在同一域中运行,但在让 SCRIPT_NAME 与 Gunicorn 正常工作时遇到问题。 示例应用程序路径: www.domain.com/app1 www.doma
$_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关
(初步说明:这个问题似乎已经有很多变体,但它们似乎都集中在物理 PHP 文件本身的文件系统位置,而不是网络 事物的 URL 位置,这就是我所追求的。) 简介 1: 我有一个小型“网站”,其物理文件系统
我不想将 GET 或 POST 变量传递给脚本。我想使用文件名并使用它从 php 脚本查找产品,例如: ....../DELL1500.php ....../COMPAQ1213.php 我有三个问题
我试图寻找差异,但每次变量都相同,有什么想法吗? 最佳答案 http://www.php.net/manual/en/reserved.variables.server.php 根据我的理解,如果您通
PHP_SELF 在包含诸如 echo $_SERVER['PHP_SELF'] 之类的代码时会为 XSS 攻击打开一个页面,但是 SCRIPT_NAME 呢? >?由于它不包含路径信息,因此可以安全
我正在维护一个经典的asp应用程序,在遍历代码时,我遇到了两行相似的代码: Request.ServerVariables("URL") ' Output: "/path/to/file.asp" R
所以我现在正在尝试在服务器上运行 Django 的多个实例,一个在 /dev/ 下,一个在 /test/ 下,等等。 网络服务器正在设置正确的 SCRIPT_NAME 设置,我可以正常提供页面、模板和
有什么区别: $_SERVER['SCRIPT_NAME'] 和 $_SERVER['PHP_SELF'] 谢谢。 最佳答案 它们应该包含相同的信息。但是,从历史和技术上来说,两者是有区别的。 SCR
我有一个简单的脚本 cpuinfo.sh 可以运行并且可执行。 我遇到了一个错误 *224 FastCGI 在标准错误中发送:“无法获取脚本名称,是否设置了 DOCUMENT_ROOT 和 SCRIP
我正在使用 Django 1.0.2 并试图弄清楚如何让@login_required 正常工作。 当我使用内置服务器时,它会按预期重定向到默认的 login_url,或我在 settings.py
我有一个 php 框架,我使用 $_SERVER['SCRIPT_NAME'] 来优化可移植性。这样我就不需要再手动配置路径了。 $this->base_url = str_replace('inde
这是我的 nginx 虚拟主机配置。 debian:~# cat /etc/nginx/sites-enabled/mybox server { listen 8080; root /
我正在 CodeIgniter 中构建一个 PHP 应用程序。 CodeIgniter 将所有请求发送到主 Controller :index.php。但是,我不喜欢在 URI 中看到 in
我正在尝试使用 mod_cgid 模块在 Apache 中部署我的 web.py 应用程序。 我在 urls.py 中定义了这样的 url urls = ( '/app/', 'index.i
我是一名优秀的程序员,十分优秀!