0

So far I've only ever developed for Apache servers but that streak is about to end and I'm having to dive into nginx. However, none of the so-called base nginx conf files seem to work for me and there's a lot of things that seem superfluous or specific to a workflow or prescribed manner of doing things. This is fine, with more experience, but when I install Craft CMS for the first time there is an .htaccess file that comes with the install that is enough to get up and running in MAMO Pro without any problems. What would the nginx conf file equivalent to this be? Once I get up and running I can worry about improving or adding things as needed but for now I just need to get basic installation up and running in MAMP Pro. Thanks.

UPDATE: I started researching nginx a little more and I think I'm beginning to understand more about how it works but at a very rudimentary level. I got Craft installed but only the home page works. Subpage links don't work and I can't access the admin site. The link is site.dev:81 (since it's nginx it's running on port 81) and the home page loads fine but clicking on a link sends the browser to site.dev/page.php.

Here's the nginx.conf file MAMP Pro creates. I see little difference between the file @khalwat links to and the one MAMP creates other then the MAMP file being more verbose. Is there anything in this conf file that would create problems for Craft and cause the url to behave in the manner described?

` 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;

MAMP_Bonjour_SubsFilter_IF_MAMP
subs_filter_types       text/html text/xml application/javascript;
MAMP_Bonjour_SubsFilter_END_MAMP

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 ~* /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 {
    server_name         MAMP_VirtualHost_ServerName_MAMP;
    listen              MAMP_IP_Port_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
    }

    MAMP_Nginx_ReverseProxy_IF_MAMP
    # proxy the PHP scripts to Apache
    location ~ \.php$ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://MAMP_Apache_IP_MAMP:MAMP_Apache_Port_MAMP;
    }
    MAMP_Nginx_ReverseProxy_ELSE_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_Nginx_ReverseProxy_END_MAMP

    MAMP_Bonjour_Substitution_IF_MAMP
    proxy_set_header Accept-Encoding "";
    subs_filter http://MAMP_Bonjour_Hostname_MAMP http://MAMP_Bonjour_DNS_Name_MAMP gi;
    subs_filter https://MAMP_Bonjour_Hostname_MAMP https://MAMP_Bonjour_DNS_Name_MAMP gi;
    MAMP_Bonjour_Substitution_END_MAMP

    MAMP_VirtualHost_AdditionalCustom_MAMP
}
MAMP_VirtualHost_iteration_end_MAMP

MAMP_SSLVirtualHost_iteration_begin_MAMP
server {
    server_name         MAMP_SSLVirtualHost_ServerName_MAMP;
    listen              MAMP_SSL_IP_Port_MAMP ssl;
    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;

    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_Nginx_ReverseProxy_IF_MAMP
    # proxy PHP scripts to Apache
    location ~ \.php$ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://MAMP_Apache_IP_MAMP:MAMP_Apache_Port_MAMP;
    }
    MAMP_Nginx_ReverseProxy_ELSE_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_Nginx_ReverseProxy_END_MAMP

    MAMP_Bonjour_Substitution_IF_MAMP
    proxy_set_header Accept-Encoding "";
    subs_filter http://MAMP_Bonjour_Hostname_MAMP http://MAMP_Bonjour_DNS_Name_MAMP gi;
    subs_filter https://MAMP_Bonjour_Hostname_MAMP https://MAMP_Bonjour_DNS_Name_MAMP gi;
    MAMP_Bonjour_Substitution_END_MAMP

    MAMP_VirtualHost_AdditionalCustom_MAMP
}
MAMP_SSLVirtualHost_iteration_end_MAMP
}

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

`

0

1 Answer 1

1

So there is Nginx-Craft which might actually be one of the configs you found, and decided there is too much superfluous stuff going on with it.

The reason I never added a basic configuration for Nginx-Craft is the local dev environment I use (Homestead) creates these configurations for you, so I've never seen the need.

In any event, I added a basic configuration to the repo for you:

https://github.com/nystudio107/nginx-craft/blob/master/sites-available/basic_localdev.com.conf

Make sure you change the fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; to reflect a path to whatever version of PHP you're running locally.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.