我在以下配置中遇到了别名位置问题
server {
listen 80;
server_name localhost;
root /srv/http/share;
index index.php;
include php.conf;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /phpmemcachedadmin {
alias /srv/http/phpmemcachedadmin;
}
location /webgrind {
alias /srv/http/webgrind;
}
}
虽然 / 运行良好,但 /webgrind 和 /phpmemcachedadmin 却出现 404 错误。如果我将根目录切换到 /srv/http 并为 / 位置设置别名,则 /phpmemcachedadmin 和 webgrind 可以运行,但 / 位置则不行。
更新:
我解决了所有位置正常工作的问题,因此这是更新后的配置
#user html;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root /srv/http/share;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
include php.conf;
}
location /phpmemcachedadmin {
root /srv/http;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
include php.conf;
}
location /webgrind {
root /srv/http;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
include php.conf;
}
}
}
php.conf 如下所示:
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
而 fastcgi.conf 如下:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
但phpmemcachedadmin 服务存在问题。如果我调用 localhost/phpmemcachedadmin/index.php,它会运行得很好(我会在访问日志中收到一个日志,表明我已在访问日志中收到文件)。另一方面,如果我只调用 localhost/phpmemcachedadmin/,它会向我提供下载文件。当我获得下载文件时,error.log 和 access.log 都不会记录任何内容。有什么想法吗?
答案1
改变
try_files $uri $uri/ /index.php$is_args$args;
到
try_files $uri $uri/ /index.php$is_args$args /index.php;
正如所说这里
答案2
我明白了...我删除了!!!try_files语句...所以我的phpmemcachedadmin配置是:
location /phpmemcachedadmin {
root /srv/http;
index index.php;
include php.conf;
}