Nginx + Magento配置问题。正在下载PHP文件

时间:2014-04-29 11:55:36

标签: php magento nginx configuration vhosts

我一直在努力让Magento在Nginx上运行。 我不是这方面的专家,但我已经使用我的Vhost配置进行了数周的故障排除。

现在我已经到了一个点,我根本不知道该怎么改变。 问题是每当我在https://mailtest.unitracer.nl/输入索引并导航到Magento时,它会尝试下载PHP文件。 这个项目必须完成,我是一家公司的实习生,我真的想学习如何实施Nginx,没有人可以帮助我,所以我真的希望这里的人能帮助我! 我在nginx中构建了两个单独的vhost文件,一个用于我的索引,一些备份文件夹我写备份,所以我可以下载它们。 另一个纯粹是为了Magento。

我会在这里发布他们的两个,包括我的nginx.conf文件。

这是我的nginx.conf文件:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # 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;
    #default_type text/html;
    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # 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/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

这是我的magento vhost文件:

    server {

    listen 80;
    listen 443 default ssl;

    server_name mailtest.unitracer.nl www.mailtest.unitracer.nl;


          ssl_certificate /etc/nginx/ssl/server.crt;
          ssl_certificate_key /etc/nginx/ssl/server.key;

    access_log  /var/log/nginx/magento.access.log;
    error_log  /var/log/nginx/magento.error.log; 


    root /var/www/magento;

    location  / {
        index index.php;
        try_files $uri $uri/ @handler;
    }

    #deny deze mappen, niemand heeft er iets te zoeken
    location /app/ { deny all; }
    location /includes/ { deny all; }
    location /lib/ { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/ { deny all; }
    location /report/config.xml { deny all; }
    location /var/ { deny all; }

    #in /var/export map moet ik user credentials instellen om /var/export te benaderen
    #in htpasswd
    location /var/export/ {
        auth_basic "Restricted";
        auth_basic_user_file htpasswd;
        autoindex on;
    }

    #Deny access hidden files
    location ~ /\. {
         deny all;
         access_log off;
         log_not_found off;
    }


    location @handler {
        rewrite / /index.php;
    }


    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }

        location ~ .php$ {
        if (!-e $request_filename) {
            rewrite / /index.php last;
        }
        expires 30d;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param HTTPS $https if_not_empty;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param MAGE_RUN_CODE default;
        fastcgi_param MAGE_RUN_TYPE store;
        include fastcgi_params;
    }
}

这是我的另一个vhost,我甚至不确定我是否需要这个,但我的索引在没有它的情况下不会显示。

server {
        listen 80;
    listen 443;

        root /var/www/;
        index index.php;
        autoindex on;

        server_name mailtest.unitracer.nl;

#SSL Directives
    ssl on;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    ssl_prefer_server_ciphers on;

#Location for index
#   location ^(.+~\.php)(/.*)$ {
#                fastcgi_split_path_info ^(.+~\.php)(/.+)$;
#              fastcgi_pass unix:/var/run/php5-fpm.sock;
#                fastcgi_index index.php;
#       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#               include fastcgi_params;
#       try_files $uri $uri/ /index.php =404;
#        }

    #Mijn back-up server block
location /backups {
                auth_basic "Restricted";
                auth_basic_user_file /var/www/backups/.htpasswd;
                try_files $uri $uri/ =404;
        }

}

我知道PHP文件已经传递到正确的PHP FPM套接字,因为之前它与phpmyadmin一起工作。

如果有人可以帮我解决这个问题的配置会很棒,我真的需要magento工作才能理解如何在Nginx上托管它!

友好的问候,

Stefan

2 个答案:

答案 0 :(得分:0)

我相信有错误 - 缺少\

location ~ \.php$ {

 expires 30d;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_param HTTPS $fastcgi_https;
fastcgi_param HTTPS $https if_not_empty;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params;
}

答案 1 :(得分:0)

删除位置上的索引index.php并在servername下设置索引index.php,它将起作用,你也可能需要添加fastcgi_split_path_info ^(。+。php)(。*)$;和fastcqi_index index.php 在locationa~.php $

相关问题