如何让 Nginx 与子目录一起工作?

如何让 Nginx 与子目录一起工作?

我想要的是:

我想在我的 Web 根目录的子文件夹中安装 Mautic。我有一个域名https://example.com我希望 Mautic 可以从https://example.com/mautic

我拥有的:

我有一台服务器

  • Ubuntu 服务器 18.04
  • Nginx 1.14.0
  • PHP 7.2
  • 通过 Certbot 进行加密
  • 基本身份验证(apache2-utils)

我得到的是:

我想在根目录的子目录中安装 Mautic(在我的情况下,Web 根目录是:)/var/www/example.com/html

但是,当我wget最新发布 Mautic 并将unzip其发布到/var/www/example.com/html/mautic,然后我浏览到https://example.com/mautic,它会重定向到https://example.com/mautic/index.php/install并在网络浏览器中返回 404。


当我curl https://example.com/mautic我明白了

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>

当我curl https://example.com/mautic/请注意!斜线添加)我得到了

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url=https://example.com/mautic/index.php/installer" />

        <title>Redirecting to https://example.com/mautic/index.php/installer</title>
    </head>
    <body>
        Redirecting to <a href="https://example.com/mautic/index.php/installer">https://example.com/mautic/index.php/installer</a>.
    </body>
</html>

的结果ls -l /var/www/example.com/html/

-rwxr-xr-x 1 root     root      612 Apr 16 08:48 index.nginx-debian.html*
drwxr-xr-x 8 www-data www-data 4096 Apr 16 08:56 mautic/

这是我的/etc/nginx/sites-enabled/example.com


server {
        root /var/www/example.com/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name example.com;
        auth_basic "My custom death threat to all tresspassers.";
        auth_basic_user_file /etc/nginx/.htpasswd;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

        #tried to play with subfolder configuration right here

        location /mautic {
        root /var/www/example.com/html;
        try_files $uri $uri/ /index.php$is_args$args;
                location ~ \.php$ {
                        include snippets/fastcgi-php.conf;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                }
        }
        location @mautic {
                rewrite /mautic/(.*)$ /mautic/index.php?/$1 last;
        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.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


}
server {
    if ($host = www.example.com) {
        rewrite (.*) https://example.com$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        server_name example.com www.example.com;
    return 404; # managed by Certbot

}

还有phpinfo()

System  Linux MYNAME 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 x86_64
Build Date  Mar 22 2019 17:05:14
Server API  FPM/FastCGI
Virtual Directory Support   disabled
Configuration File (php.ini) Path   /etc/php/7.2/fpm
Loaded Configuration File   /etc/php/7.2/fpm/php.ini
Scan this dir for additional .ini files     /etc/php/7.2/fpm/conf.d
Additional .ini files parsed    /etc/php/7.2/fpm/conf.d/10-mysqlnd.ini, /etc/php/7.2/fpm/conf.d/10-opcache.ini, /etc/php/7.2/fpm/conf.d/10-pdo.ini, /etc/php/7.2/fpm/conf.d/15-xml.ini, /etc/php/7.2/fpm/conf.d/20-bz2.ini, /etc/php/7.2/fpm/conf.d/20-calendar.ini, /etc/php/7.2/fpm/conf.d/20-ctype.ini, /etc/php/7.2/fpm/conf.d/20-curl.ini, /etc/php/7.2/fpm/conf.d/20-dom.ini, /etc/php/7.2/fpm/conf.d/20-exif.ini, /etc/php/7.2/fpm/conf.d/20-fileinfo.ini, /etc/php/7.2/fpm/conf.d/20-ftp.ini, /etc/php/7.2/fpm/conf.d/20-gd.ini, /etc/php/7.2/fpm/conf.d/20-gettext.ini, /etc/php/7.2/fpm/conf.d/20-iconv.ini, /etc/php/7.2/fpm/conf.d/20-imap.ini, /etc/php/7.2/fpm/conf.d/20-intl.ini, /etc/php/7.2/fpm/conf.d/20-json.ini, /etc/php/7.2/fpm/conf.d/20-mbstring.ini, /etc/php/7.2/fpm/conf.d/20-mysqli.ini, /etc/php/7.2/fpm/conf.d/20-pdo_mysql.ini, /etc/php/7.2/fpm/conf.d/20-phar.ini, /etc/php/7.2/fpm/conf.d/20-posix.ini, /etc/php/7.2/fpm/conf.d/20-readline.ini, /etc/php/7.2/fpm/conf.d/20-shmop.ini, /etc/php/7.2/fpm/conf.d/20-simplexml.ini, /etc/php/7.2/fpm/conf.d/20-sockets.ini, /etc/php/7.2/fpm/conf.d/20-sysvmsg.ini, /etc/php/7.2/fpm/conf.d/20-sysvsem.ini, /etc/php/7.2/fpm/conf.d/20-sysvshm.ini, /etc/php/7.2/fpm/conf.d/20-tokenizer.ini, /etc/php/7.2/fpm/conf.d/20-wddx.ini, /etc/php/7.2/fpm/conf.d/20-xmlreader.ini, /etc/php/7.2/fpm/conf.d/20-xmlwriter.ini, /etc/php/7.2/fpm/conf.d/20-xsl.ini, /etc/php/7.2/fpm/conf.d/20-zip.ini
PHP API     20170718
PHP Extension   20170718
Zend Extension  320170718
Zend Extension Build    API320170718,NTS
PHP Extension Build     API20170718,NTS
Debug Build     no
Thread Safety   disabled
Zend Signal Handling    enabled
Zend Memory Manager     enabled
Zend Multibyte Support  provided by mbstring
IPv6 Support    enabled
DTrace Support  available, disabled
Registered PHP Streams  https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters   zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*, bzip2.*, convert.iconv.* 

我不知道我做错了什么。如何让 Mautic 安装程序在子文件夹中工作?谢谢!

更新 1

Nginxerror.log

2019/04/16 14:18:10 [notice] 17193#17193: signal process started
2019/04/16 14:18:29 [notice] 17225#17225: signal process started
2019/04/16 15:46:08 [notice] 18855#18855: signal process started
2019/04/16 15:47:20 [notice] 18901#18901: signal process started
2019/04/16 15:52:37 [crit] 18902#18902: *30 SSL_do_handshake() failed (SSL: error:1417D18C:SSL routines:tls_process_client_hello:version too low) while SSL handshaking, client: 184.105.247.194, server: 0.0.0.0:443

access.log

94.75.108.40 - user [16/Apr/2019:14:18:36 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:18:36 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:18:36 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:18:36 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:18:36 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
my.server.ip.address - user [16/Apr/2019:14:19:26 +0200] "GET /mautic HTTP/1.1" 301 194 "-" "curl/7.58.0"
my.server.ip.address - user [16/Apr/2019:14:19:47 +0200] "GET / HTTP/1.1" 200 612 "-" "curl/7.58.0"
94.75.108.40 - user [16/Apr/2019:14:20:55 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:20:55 +0200] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
171.13.14.46 - - [16/Apr/2019:14:38:22 +0200] "CONNECT 133.130.126.119:43 HTTP/1.1" 400 182 "-" "-"
94.75.108.40 - user [16/Apr/2019:14:59:50 +0200] "GET /mautic/ HTTP/1.1" 302 424 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:59:50 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:14:59:50 +0200] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
my.server.ip.address - user [16/Apr/2019:15:00:13 +0200] "GET /mautic HTTP/1.1" 301 194 "-" "curl/7.58.0"
my.server.ip.address - user [16/Apr/2019:15:00:22 +0200] "GET /mautic/ HTTP/1.1" 302 424 "-" "curl/7.58.0"
my.server.ip.address - user [16/Apr/2019:15:00:33 +0200] "GET /mautic/index.php HTTP/1.1" 302 464 "-" "curl/7.58.0"
94.75.108.40 - user [16/Apr/2019:15:26:58 +0200] "GET /info.php HTTP/1.1" 200 26052 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:26:58 +0200] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:46:12 +0200] "GET / HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:46:12 +0200] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:46:16 +0200] "GET /mautic/ HTTP/1.1" 302 424 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:46:16 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:46:21 +0200] "GET /mautic/index.php/installer HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:46:25 +0200] "GET / HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - user [16/Apr/2019:15:47:23 +0200] "GET / HTTP/1.1" 200 396 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - - [16/Apr/2019:15:48:29 +0200] "GET /mautic/ HTTP/1.1" 401 204 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
94.75.108.40 - - [16/Apr/2019:15:48:29 +0200] "GET /favicon.ico HTTP/1.1" 401 204 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"

更新2

只是为了测试,我尝试了许多其他自托管产品(例如 InfiniteWP),它们都运行正常。

答案1

真是笑话。在 Nginx 中error.log我终于找到了答案:

我没有chmod 777安装过程中需要的文件夹。:D 真是失败。

相关内容