gpt4 book ai didi

Nginx 位置指令似乎不起作用。我错过了什么吗?

转载 作者:行者123 更新时间:2023-12-03 07:37:06 26 4
gpt4 key购买 nike

我已经将 Nginx 设置为我的主要 Web 服务器,并在其后面有两个基于 Mochiweb 的服务器。某些请求被反向代理到这两个服务器。现在,我想使用nginx访问phpmyadmin(位于/var/www/nginx-default/phpMyAdmin),但它一直显示错误404未找到。我在这里遗漏了一些明显的东西吗?

server {
############### General Settings ####################
listen 80;
server_name localhost;
access_log /home/me/dev/wwwaccess.log;

############## Document Root #######################
location / {
root /home/me/dev;
index index.html index.htm index.php;
}

############## PHPMyAdmin #######################
location /phpmyadmin {
root /var/www/nginx-default/phpMyAdmin;
index index.html index.htm index.php;
}

############## Proxy Settings for FastCGI Server #####
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/me/dev$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}


############# Proxy Settings for Mochi1 ###############
location /mochi1 {
proxy_pass http://127.0.0.1:8000;
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;

client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 3600;

proxy_buffering off;
}

############# Proxy Settings for Mochi2 ###############
location /mochi2 {
proxy_pass http://127.0.0.1:8001;
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;

client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 3600;

proxy_buffering off;
}

############# Error redirection pages ################
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/me/dev;
}
}

最佳答案

这里的问题是,只有“最佳”location 指令被采用,按以下顺序:

location =  <path>  (longest match wins)
location ^~ <path> (longest match wins)
location ~ <path> (first defined match wins)
location <path> (longest match wins)

使用此规则集,您的 /phpmyadmin location 指令将被正则表达式“.php$”击败location 指令,因此前者被完全忽略。此外,您的 php fastcgi 指令硬连接到您的 /home/me/dev 目录,这意味着 phpMyAdmin 完全无法访问。您可以使用重写来获取 phpMyAdmin 脚本的正确根目录:

location ~ \.php$ {
set $php_root /home/me/dev;
if ($request_uri ~* /phpmyadmin) {
set $php_root /var/www/nginx-default/phpMyAdmin;
}

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

关于Nginx 位置指令似乎不起作用。我错过了什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1011101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com