简体   繁体   English

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

[英]Nginx + Magento configuration problems. PHP files are being downloaded

I've been fighting to get Magento to run on Nginx. 我一直在努力让Magento在Nginx上运行。 I'm not an expert at this but I've been troubleshooting with my Vhost configurations for weeks. 我不是专家,但已经对Vhost配置进行了数周的故障排除。

Right now I've gotten to a point where I simply don't know what to change anymore. 现在,我已经到了根本不知道要更改什么的地步。 The problem is that whenever I enter my index at https://mailtest.unitracer.nl/ and navigate to Magento it tries to download PHP files. 问题是,每当我在https://mailtest.unitracer.nl/输入索引并导航到Magento时,它都会尝试下载PHP文件。 This project has to be finished, I'm an intern at a company where I really want to learn how to implement Nginx, no one can help me with it here, so I really hope the people here can help me out! 这个项目必须完成,我是一家公司的实习生,我真的想学习如何实现Nginx,在这里没有人可以帮助我,所以我真的希望在这里的人能帮助我! I build two seperate vhost files in nginx, one for my index and some back-up folder that I write backups to so I can download them. 我在nginx中构建了两个单独的虚拟主机文件,一个用于我的索引,另一个用于写备份的备份文件夹,以便我可以下载它们。 The other one is purely for Magento. 另一个纯粹是针对Magento的。

I'll post both of them here including my nginx.conf file. 我将把它们都发布在这里,包括我的nginx.conf文件。

Here is my nginx.conf file: 这是我的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;
#   }
#}

Here is my magento vhost file: 这是我的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;
    }
}

Here is my other vhost, i'm not even sure if I need this one but my index won't show without it. 这是我的另一个虚拟主机,我什至不确定我是否需要这个虚拟主机,但是没有它我的索引将不会显示。

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

}

I know that PHP files have been passed to the correct PHP FPM socket because it worked with phpmyadmin before. 我知道PHP文件已经传递到正确的PHP FPM套接字,因为它以前与phpmyadmin一起使用。

It would be great if someone could help me with the configuration of this problem, I really need magento to work so that I understand how to host it on Nginx! 如果有人可以帮助我解决此问题,那将非常好,我确实需要magento才能工作,以便我了解如何在Nginx上托管它!

Friendly greetings, 友好的问候,

Stefan 斯特凡

I believe there is mistake - missing \\ 相信有误-遗失\\

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

remove index index.php on location / and set index index.php under servername and it will work it is also possible that you need to add fastcgi_split_path_info ^(.+.php)(.*)$; 删除位置/上的index index.php并在服务器名下设置index index.php,它将起作用,也有可能需要添加fastcgi_split_path_info ^(。+。php)(。*)$; and fastcqi_index index.php at locationa ~ .php$ 和fastcqi_index index.php在locationa〜.php $

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM