我一直在努力让Magento在Nginx上运行。我不是这方面的专家,但我已经对Vhost配置进行了数周的故障排除。
现在我已经到了一个地步,我根本不知道该改变什么。问题是,每当我在https://mailtest.unitracer.nl/并导航到Magento,它尝试下载PHP文件。这个项目必须完成,我是一家公司的实习生,我真的很想学习如何实现Nginx,这里没有人能帮我,所以我真的希望这里的人能帮助我!我在nginx中构建了两个独立的vhost文件,一个用于我的索引,另一个用于编写备份的备份文件夹,以便下载它们。另一个纯粹是给马根托的。
我将把它们都发布在这里,包括我的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
我认为有错误-丢失''
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;
}
删除location/上的index index.php,并在servername下设置index index.php就可以了。也可能需要添加fastcgi_split_path_info^(++.php((.*($;和fastcqi_index index.php位置a~.php$