如何在 MAMP 上设置 NGINX WordPress 多站点?

问题描述 投票:0回答:0

我一直在尝试在 MAMP Pro 上为带有子目录的 WordPress Multisite 创建一个 Nginx 环境。我能够完成创建 WordPress 多站点的大部分步骤,但是我意识到 Nginx 不使用 htaccesss,而是根据其文档更新其所需的 nginx.conf 文件:https://wordpress.org/documentation/文章/nginx/。我相信这会阻止我访问我的第二个子站点 wp-admin 仪表板并导致我的第二个子站点为每个外部链接和样式表返回 404(未找到)错误(我已经检查了数据库站点 url 和博客 url 已设置正确)。

我已经尝试进行更改,但也可能是我做错了,因为这是我第一次尝试这样做。

所以我想知道是否有人可以指出需要添加哪些指令以及在哪里添加?我附上了 MAMP nginx.conf 的副本以供参考,我相信也可以通过 MAMP GUI 仪表板添加一些指令,所以我将附上我所看到的截图以供参考。

Nginx.conf

MAMP_ngx_http_image_filter_module_MAMPload_module "modules/ngx_http_image_filter_module.so";
MAMP_ngx_http_perl_module_MAMPload_module "modules/ngx_http_perl_module.so";
MAMP_ngx_http_xslt_filter_module_MAMPload_module "modules/ngx_http_xslt_filter_module.so";
MAMP_ngx_mail_module_MAMPload_module "modules/ngx_mail_module.so";
MAMP_ngx_stream_module_MAMPload_module "modules/ngx_stream_module.so";

MAMP_User_Directive_MAMPuser                        MAMP_User_MAMP MAMP_Group_MAMP;
worker_processes            auto;

events {
    worker_connections      1024;
}

http {
    include                 /Applications/MAMP/conf/nginx/mime.types;
    default_type            text/html;
    gzip                    on;
    gzip_types              text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    
    sendfile                on;
    keepalive_timeout       65;

    # access_log            "/Applications/MAMP/logs/nginx_access.log";
    error_log               "MAMP_NginxErrorLog_MAMP";

    server_names_hash_bucket_size  128;

    # Enables or disables stapling of OCSP responses by the server. Example:
    #ssl_stapling on | off;

    # Enables or disables verification of OCSP responses by the server
    #ssl_stapling_verify on | off;

    server {
        listen              MAMP_Port_MAMP default_server;
        listen              MAMP_SSL_Port_MAMP default_server ssl;
        ssl_ciphers         'aNULL';
        ssl_certificate     "/Applications/MAMP/conf/server/default.crt";
        ssl_certificate_key "/Applications/MAMP/conf/server/default.key";

        return 444;
    }

    server {
        listen              MAMP_Port_MAMP;
        server_name         localhost;

        root                "MAMP_Localhost_DocumentRoot_MAMP";

        location / {
            index            MAMP_Localhost_DirectoryIndex_MAMP;
        }
    
        location ~* /MAMP([^-].*)$ {
            root             "/Library/Application Support/appsolute/MAMP PRO";
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          /Applications/MAMP/conf/nginx/fastcgi_params;
            }
        }

        location ~* /phpMyAdmin(.*)$ {
            root             "/Library/Application Support/appsolute/MAMP PRO";
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          /Applications/MAMP/conf/nginx/fastcgi_params;
            }
        }

        location ~* /phpMyAdmin5(.*)$ {
            root             "/Library/Application Support/appsolute/MAMP PRO";
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          /Applications/MAMP/conf/nginx/fastcgi_params;
            }
        }

        location ~* /phpPgAdmin(.*)$ {
            root             /Applications/MAMP/bin;
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          /Applications/MAMP/conf/nginx/fastcgi_params;
            }
        }
        
        location ~* /phpLiteAdmin(.*)$ {
            root             /Applications/MAMP/bin;
            index            index.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          /Applications/MAMP/conf/nginx/fastcgi_params;
            }
        }
        
        location ~* /adminer(.*)$ {
            root             /Applications/MAMP/bin;
            index            adminer.php;

            location ~ \.php$ {
                try_files        $uri =404;
                fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
                fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include          /Applications/MAMP/conf/nginx/fastcgi_params;
            }
        }
        
        location /icons {
            alias /Applications/MAMP/Library/icons;
            autoindex on;
        }
        
        location /favicon.ico {
            alias /Applications/MAMP/bin/favicon.ico;
            # log_not_found off;
            # access_log off;
        }

        location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpLocalhost_MAMP.sock;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          /Applications/MAMP/conf/nginx/fastcgi_params;
        }

        location ~ /\. {
            deny all;
        }

        # location ~* \.(gif|jpg|png|pdf)$ {
        #     expires          30d;
        # }

        # location = /robots.txt {
        #     allow all;
        #     log_not_found off;
        #     access_log off;
        # }

        # location ~* \.(txt|log)$ {
        #     allow 127.0.0.1;
        #     deny all;
        # }

        # location ~ \..*/.*\.php$ {
        #     return 403;
        # }

        location /nginx_status {
            stub_status      on;
            access_log       off;
            allow            127.0.0.1;
            deny             all;
        }
    }

    MAMP_VirtualHost_iteration_begin_MAMP
    server {
        listen              MAMP_IP_Port_MAMP;
        server_name         MAMP_VirtualHost_ServerName_MAMP;
        MAMP_VirtualHost_ServerAliases_MAMP

        root                "MAMP_VirtualHost_DocumentRoot_MAMP";

        location / {
            try_files       MAMP_Try_Files_MAMP;
            index           MAMP_VirtualHost_DirectoryIndex_MAMP;
            autoindex       MAMP_VirtualHost_AutoIndex_MAMP;
            MAMP_VirtualHost_Allow_MAMP
            MAMP_VirtualHost_Deny_MAMP
            MAMP_LocationCustom_MAMP
        }

        location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpHost_MAMP.sock;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          /Applications/MAMP/conf/nginx/fastcgi_params;
        }

        MAMP_VirtualHost_AdditionalCustom_MAMP
    }
    MAMP_VirtualHost_iteration_end_MAMP

    MAMP_SSLVirtualHost_iteration_begin_MAMP
    server {
        listen              MAMP_SSL_IP_Port_MAMP ssl;
        server_name         MAMP_SSLVirtualHost_ServerName_MAMP;
        client_max_body_size 0;
        MAMP_SSLVirtualHost_ServerAliases_MAMP

        root                "MAMP_SSLVirtualHost_DocumentRoot_MAMP";
        # access_log          "/Applications/MAMP/logs/nginx_ssl_access.log";
        error_log           "/Applications/MAMP/logs/nginx_ssl_error.log";

        ssl_certificate     "MAMP_SSLVirtualHost_Certificate_MAMP";
        ssl_certificate_key "MAMP_SSLVirtualHost_CertificateKey_MAMP";
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_session_tickets off;

        MAMP_SSLVirtualHost_OnlyAllowTLS_MAMPssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        MAMP_SSLVirtualHost_OnlyAllowTLS_MAMPssl_ciphers         'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
        MAMP_SSLVirtualHost_OnlyAllowTLS_MAMPssl_prefer_server_ciphers  on;
        MAMP_SSLVirtualHost_OnlyAllowTLS_MAMPadd_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

        location / {
            try_files       MAMP_Try_Files_MAMP;
            index           MAMP_SSLVirtualHost_DirectoryIndex_MAMP;
            autoindex       MAMP_VirtualHost_AutoIndex_MAMP;
            MAMP_VirtualHost_Allow_MAMP
            MAMP_VirtualHost_Deny_MAMP
            MAMP_LocationCustom_MAMP
        }

        location ~ \.php$ {
            try_files        $uri =404;
            fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_phpMAMP_PhpHost_MAMP.sock;
            fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include          /Applications/MAMP/conf/nginx/fastcgi_params;
        }

        MAMP_VirtualHost_AdditionalCustom_MAMP
    }
    MAMP_SSLVirtualHost_iteration_end_MAMP
}

# DONT REMOVE: MAMP PRO nginx.conf template compatibility version: 23

我试图将此链接中的代码复制并粘贴到 nginx.conf 文件和 MAMP 应用程序 GUI PER 中的不同位置:https://wordpress.org/documentation/article/nginx/#wordpress-multisite -子目录规则。但我觉得我没有正确添加它,因为 nginx 是我不熟悉的东西。

wordpress nginx nginx-config multisite mamp-pro
© www.soinside.com 2019 - 2024. All rights reserved.