【问题标题】:Nginx + Magento configuration problems. PHP files are being downloadedNginx + Magento 配置问题。正在下载 PHP 文件
【发布时间】:2014-06-15 08:24:51
【问题描述】:

我一直在努力让 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 虚拟主机文件:

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

这是我的另一个虚拟主机,我什至不确定我是否需要这个,但没有它我的索引不会显示。

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 上托管它!

友好的问候,

斯蒂芬

【问题讨论】:

    标签: php magento nginx configuration vhosts


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我认为有错误 - 缺少\

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

      【讨论】:

        猜你喜欢
        • 2012-03-17
        • 1970-01-01
        • 1970-01-01
        • 2021-12-15
        • 1970-01-01
        • 2023-04-10
        • 2011-02-07
        • 1970-01-01
        • 2019-07-21
        相关资源
        最近更新 更多