Nginx

如何讓 Nginx 使用子目錄?ñG,Le___噸′小號_ncy_pt,basicauthñG一世nX,大號和噸′s和nCr是p噸,b一種s一世C一種在噸HNginx, Let’s Encrypt, basic auth

  • April 18, 2019

我想要的是:

我想將 Mautic 安裝在我的 Web 根目錄的子文件夾中。我有一個域https://example.com>並且我希望能從<https://example.com/mautic訪問 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我得到

&lt;html&gt;
&lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor="white"&gt;
&lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.14.0 (Ubuntu)&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;

當我curl https://example.com/mautic/(*請注意!*斜線添加)我得到

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

       &lt;title&gt;Redirecting to https://example.com/mautic/index.php/installer&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
       Redirecting to &lt;a href="https://example.com/mautic/index.php/installer"&gt;https://example.com/mautic/index.php/installer&lt;/a&gt;.
   &lt;/body&gt;
&lt;/html&gt;

的結果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),它們都可以正常工作。

真是笑話。在 Nginxerror.log中,我終於找到了答案:

我沒有chmod 777安裝處理所需的文件夾。:D 多麼失敗。

引用自:https://serverfault.com/questions/963306