【发布时间】:2018-05-31 14:18:32
【问题描述】:
在我尽力解释这一点时,您将不得不在这里忍受我。
我正在使用我没有设置的 nginx 服务器,我对 nginx 知之甚少。我已经建立了一个新的 wordpress 网站,它位于以下 url 结构 subsubdomain.subdomain.domain.com/website/ 下,重要的是完整的 wordpress 网站在 /website/ 目录中正常运行。
当我导航到subsubdomain.subdomain.domain.com/website/ 时,我已经设置了站点并且主页运行良好,但是当我导航到子页面subsubdomain.subdomain.domain.com/website/resources/ 时,服务器会抛出File not found。
根据我对 nginx 的一点了解,我认为这是一个文件权限问题,我已经登录到服务器并运行以下命令 sudo chmod 777 -R /path/to/website 并还完成了 sudo chown www:www -R /path/to/website 以尝试授予完全访问权限。不幸的是,这也没有奏效。
查看网站access_log 和error_log 时,它们是空的。然后我查看了nginx主日志文件,发现如下错误:
2018/05/31 04:07:42 [crit] 32426#0: *120 open() "/usr/share/nginx//var/www/sites-running/subsubdomain.subdomain.website.com/logs/nginx.access.log" failed (2: No such file or directory) while logging request, client: **.***.***.***, server: *.subdomain.domain.com, request: "GET /website/resources/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "subsubdomain.subdomain.domain.com", referrer: "http://subsubdomain.subdomain.domain.com/website/"
老实说,这对我来说毫无意义。我所看到的只是日志文件的路径看起来很糟糕。所以我去我的网站nginx-vhost.conf文件看看它是如何定义的,我有以下代码:
access_log /var/www/sites-running/subsubdomain.subdomain.website.com/logs/nginx.access.log
我觉得这一切都很好。
所以现在我被卡住了,我不知道如何解决这个问题,所以如果有人能理解这一点并能帮助我,那就太棒了。
干杯, 卢克。
更新
我刚刚运行nginx -V,注意到有一个值叫做prefix,这是值:
--prefix=/usr/share/nginx
看起来这可能是我的问题,但我不知道这是什么,如何使用它,也不知道如果我改变它可能造成的损害。
更新
这是我的网站 nginx-vhost.conf 文件。
# Nginx configuration for Website
# This is for development purposes
server{
listen 80;
server_name subsubdomain.subdomain.domain.com;
set $site_root "/var/www/sites-available/$host";
set $public_html "$site_root/public_html";
set $logs_dir "$site_root/logs";
set $nginx_root "$site_root/webapps/ROOT";
root $nginx_root;
error_log /var/www/sites-available/subsubdomain.subdomain.domain.com/logs/nginx.error.log;
access_log /var/www/sites-available/subsubdomain.subdomain.domain.com/logs/nginx.access.log main;
index index.php;
#default_type text/html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
#add_header 'Access-Control-Allow-Origin' "*";
# ------------------------------------------------------
#
# static resources routing for version control on assets
#
# ------------------------------------------------------
#location ~ ^/static/([^/]+)/(content|resources)/(.*)$ {
# alias $public_html/$2/$3;
#}
#location ~ ^/content/(.*)$ {
# alias $public_html/content/$1;
#}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location /wp-admin {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /wp-admin/index.php?$args;
}
# ----------------------------------------
#
# PHP
#
# ----------------------------------------
location ~ \.php {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SERVER_NAME $host;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param CONTENT_ROOT $public_html/content;
fastcgi_param CONTENT_UPLOAD_DIR $public_html/content;
fastcgi_param LOGS_ROOT $logs_dir;
fastcgi_param app.profile staging;
fastcgi_param APP_MODE staging;
fastcgi_param DB_NAME **********;
fastcgi_param DB_USER **********;
fastcgi_param DB_PASS **********;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
这是我的主要 nginx.conf 文件
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
server_names_hash_bucket_size 128;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 100m;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;
#root /var/www/sites-running/nginx-default;
#index index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# location / {
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# root html;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# }
#}
}
【问题讨论】:
-
如果你希望得到一些帮助,那么你需要分享你的 nginx.conf
-
你能分享你的主机文件吗?所以我们可以看到你拥有的 index.php 规则。 codex.wordpress.org/Nginx 您需要检查一下,以及管理员设置中的站点 URL 是什么
-
@AlexC & @TheBlackBenzKid - 我已经添加了我的配置文件,我认为这就是你们俩所要求的。由于这是从本地 wordpress 站点到临时 wordpress 站点的部署,我在数据库中进行了查找和替换,将
http://localhost:8888/更改为http://subsubdomain.subdomain.domain.com/website/ -
那么这个呢。
try_files $uri $uri/ /wp-admin/index.php?$args;变成try_files $uri $uri/ /index.php?$args;。不过还是猜测 -
@ippi - 非常接近,我刚刚设法弄清楚,我必须添加以下
try_files $uri $uri/website/ /website/index.php?$args;