Nginx 默认为 /usr/share/nginx/html

Wil*_*ord 9 linux nginx wordpress ubuntu-18.04

这是一个开发站点。推送到现场环境在我今天早上的备份中工作。

系统

  1. Ubuntu 18.04

  2. nginx

  3. PHP 7.2

  4. MYSQL

正在努力删除 TLSv1 表单证书路径。删除它并测试工作正常。正在使用一个插件来重新应用 API,因此它会回调正确的 url。现在我只是获得默认的 Nginx 页面。我已从备份恢复到新服务器并且站点正在运行。我正在做分类,似乎无法弄清楚到底发生了什么。

以下是 NGINX 的错误日志:

2018/07/13 19:37:01 [error] 4593#4593: *206 open() "/usr/share/nginx/html/wp-admin/admin-ajax.php" failed (2: No such file or directory), client: 65.152.214.10, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", host: "smokingquartz.com", referrer: "https://smokingquartz.com/wp-admin/plugins.php"
2018/07/13 19:39:01 [error] 4593#4593: *211 open() "/usr/share/nginx/html/wp-admin/admin-ajax.php" failed (2: No such file or directory), client: 65.152.214.10, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", host: "smokingquartz.com", referrer: "https://smokingquartz.com/wp-admin/plugins.php"
2018/07/13 19:41:02 [error] 4593#4593: *213 open() "/usr/share/nginx/html/wp-admin/admin-ajax.php" failed (2: No such file or directory), client: 65.152.214.10, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", host: "smokingquartz.com", referrer: "https://smokingquartz.com/wp-admin/plugins.php"
2018/07/13 19:43:03 [error] 4593#4593: *215 open() "/usr/share/nginx/html/wp-admin/admin-ajax.php" failed (2: No such file or directory), client: 65.152.214.10, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", host: "smokingquartz.com", referrer: "https://smokingquartz.com/wp-admin/plugins.php"
2018/07/13 19:44:09 [error] 4593#4593: *218 open() "/usr/share/nginx/html/phpmyadmin/index.php" failed (2: No such file or directory), client: 96.88.66.233, server: , request: "POST /phpmyadmin/index.php HTTP/1.1", host: "smokingquartz.com"
2018/07/13 19:45:03 [error] 4593#4593: *220 open() "/usr/share/nginx/html/wp-admin/admin-ajax.php" failed (2: No such file or directory), client: 65.152.214.10, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", host: "smokingquartz.com", referrer: "https://smokingquartz.com/wp-admin/plugins.php"
2018/07/13 19:47:03 [error] 4593#4593: *222 open() "/usr/share/nginx/html/wp-admin/admin-ajax.php" failed (2: No such file or directory), client: 65.152.214.10, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", host: "smokingquartz.com", referrer: "https://smokingquartz.com/wp-admin/plugins.php"
Run Code Online (Sandbox Code Playgroud)

看来我的根文件夹已更改为/usr/share/nginx/html。这不是我可用/启用的站点中配置的内容。

可用站点:

server {
## Basic Info ##
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name smokingquartz.com www.smokingquartz.com;
    index index.php index.html index.htm index.nginx-debian.html;
    root /var/www/html/smokingquartz/;

## WP Defender - Prevent PHP Execution ##
    # Stop php access except to needed files in wp-includes
    location ~* ^/wp-includes/.*(?<!(js/tinymce/wp-tinymce))\.php$ {
        internal; #internal allows ms-files.php rewrite in multisite to work
    }

    # Specifically locks down upload directories in case full wp-content rule below is skipped
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
        }

    # Deny direct access to .php files in the /wp-content/ directory (including sub-folders).
    #  Note this can break some poorly coded plugins/themes, replace the plugin or remove this block if it causes trouble
    location ~* ^/wp-content/.*\.php$ {
        deny all;
    }            
## WP Defender - End ##

## Rewrite for sitemap ##
    rewrite ^/(.*/)?sitemap.xml /wp-content/uploads/sitemap.xml last;

## exact-matching loctation blocks ##
    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(txt|xml|js)$ {expires 8d;}
    location ~* \.(css)$ {expires 8d;}
    location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|svg)$ {expires 8d;}
    location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {expires 8d;}
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;
    }

## pass PHP scripts to FastCGI server ##
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        # With php-cgi (or other tcp sockets):
        #fastcgi_pass 127.0.0.1:9000;
    }

## deny access to .htaccess files, if Apache's document root ##
## concurs with nginx's one ##
    location ~ /\.ht {
        deny all;
    }
## GZIP ##  
    gzip on;
        gzip_comp_level    5;
        gzip_min_length    256;
        gzip_proxied       any;
        gzip_vary          on;

    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        text/x-cross-domain-policy;
        # text/html is always compressed by gzip module}server{
listen [::]:443 ssl ipv6only=on ; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/smokingquartz.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/smokingquartz.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot}
Run Code Online (Sandbox Code Playgroud)

我将其与备份文件进行了比较,它们是相同的。

这是 NGINX.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
client_max_body_size 32M;
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Humming Bird Cache
##


server{

rewrite ^/(.*/)?sitemap.xml /wp-content/uploads/sitemap.xml last;

location ~* \.(txt|xml|js)$ {
   expires 8d;
}

location ~* \.(css)$ {
    expires 8d;
}

location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|svg)$ {
    expires 10d;
}

location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {
    expires 8d;
}
}
##
# Gzip Settings
##

# Enable Gzip compression
gzip          on;

# Compression level (1-9)
gzip_comp_level     5;

# Don't compress anything under 256 bytes
gzip_min_length     256;

# Compress output of these MIME-types
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-font-opentype
application/x-font-truetype
application/x-javascript
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/eot
font/opentype
font/otf
image/svg+xml
image/x-icon
image/vnd.microsoft.icon
text/css
text/plain
text/javascript
text/x-component;

# Disable gzip for bad browsers
gzip_disable  "MSIE [1-6]\.(?!.*SV1)";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Run Code Online (Sandbox Code Playgroud)

如果您还需要其他任何东西,请告诉我这个问题让我难住了。

****编辑更正的错别字:“Nginix”到 Nginx ****

Pie*_*erz 7

在 Nginx 中,如果locationuri没有匹配项,那么它通常默认查找/usr/share/nginx/html/(与 OpenResty 类似/usr/openresty/nginx/html/)。因此,它似乎与您的 URI 之一不匹配并退回到默认位置。

找出默认位置的最简单方法是运行(正如@Snidhi 所评论的,该-V选项现在取代了-h用于此目的的选项):

nginx -V
Run Code Online (Sandbox Code Playgroud)

可以通过在响应中显示的路径并在--prefix其后附加“html”来找到默认位置。

如果您只创建一个没有任何location条目的最小 nginx.conf 文件并在调试模式下运行它,您就会看到这种行为:

# Put in file /tmp/nginx-test.conf
error_log /dev/stderr debug;
daemon off;

events {
    worker_connections 1024;
}
http {
    server {
        listen 8080;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后运行服务器:

sudo nginx  -c /tmp/nginx-test.conf
Run Code Online (Sandbox Code Playgroud)

你会看到所有的请求(例如在另一个窗口中:)

curl http://127.0.0.1:8080/test
Run Code Online (Sandbox Code Playgroud)

尝试从 /usr/share/nginx/html/

  • 对于此线程的未来读者:要查找默认前缀,$ nginx -V(并查找 --prefix 的值。它会显示类似 /usr/share/nginx/html/ 的内容)。 (3认同)

Leo*_*Leo 0

您应该禁用在site-enabled中预先配置的默认站点:

/etc/nginx/sites-enabled/default
Run Code Online (Sandbox Code Playgroud)

关于您的问题,您列出的site-availablenotenabled

除非您使用相同的默认文件并覆盖您自己的虚拟主机的参数,否则您应该简单地从启用站点的符号链接中删除符号链接:

sudo rm /etc/nginx/sites-enabled/default
Run Code Online (Sandbox Code Playgroud)

并重新加载 nginx:

sudo systemctl reload nginx
Run Code Online (Sandbox Code Playgroud)