当我尝试尽力解释时,你将不得不忍受我。
我正在使用我没有设置的nginx服务器,我对nginx知之甚少。我已经建立了一个新的wordpress网站,它位于以下网址结构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 / {
# }
#}
}
答案 0 :(得分:1)
感谢大家的帮助。我终于设法弄清楚出了什么问题。我需要更新我的conf文件以获得第二个位置语句,该语句查看/website/
文件夹。
location /website/ {
# 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/website/ /website/index.php?$args;
}
这是我的完整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 /website/ {
# 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/website/ /website/index.php?$args;
}
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;
}
}