Magento和nginx-多网站配置
现在,我直接在我的Magento多网站中为nginx使用下面的配置。一切都很好,但我不喜欢这种配置没有优化,结果是非常巨大的。正如您所看到的,两个服务器配置几乎相同,只有服务器名称、ssl和fastcgi_参数MAGE_RUN_代码不同。如何加入2个服务器配置?正如你所看到的,这里有很多重复Magento和nginx-多网站配置,magento,nginx,Magento,Nginx,现在,我直接在我的Magento多网站中为nginx使用下面的配置。一切都很好,但我不喜欢这种配置没有优化,结果是非常巨大的。正如您所看到的,两个服务器配置几乎相同,只有服务器名称、ssl和fastcgi_参数MAGE_RUN_代码不同。如何加入2个服务器配置?正如你所看到的,这里有很多重复 server { listen 80; server_name test.com test1.com; rewrite / $scheme://www.$host$request_u
server {
listen 80;
server_name test.com test1.com;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}
server {
listen 80;
## SSL directives might go here
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/test/cert.cer;
ssl_certificate_key /etc/nginx/ssl/private/test.key;
server_name www.test.com test.com;
root /var/www/test;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
## These locations would be hidden by .htaccess normally
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; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
error_page 403 /error-page.html;
error_page 502 /error-page.html;
error_page 503 /error-page.html;
error_page 504 /error-page.html;
}
server {
listen 80;
## SSL directives might go here
listen 443 ssl;
server_name test1.com www.test1.com;
root /var/www/test;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
## These locations would be hidden by .htaccess normally
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; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE test1; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
error_page 403 /error-page.html;
error_page 502 /error-page.html;
error_page 503 /error-page.html;
error_page 504 /error-page.html;
}
这取决于您在Ubuntu中使用的发行版,
/etc/nginx/nginx.conf
文件添加此条目包括/etc/nginx/sites enabled/*代码>内部http{}节
然后在include/etc/nginx/sites enabled/
希望这会有所帮助。我曾考虑过为您重写整个配置文件,但是,如果您只是简单地从web上复制粘贴一些内容,这将是一个坏主意,而且可能会违反StackOverflow应答格式的精神
所以,让我给你们一些很好的建议,告诉你们如何在一般意义上自己完成你们所需要的
另外,一般来说,就nginx和性能而言,拥有多个几乎相同的server
指令并不是一个坏主意-它们只是从管理的角度来看是不好的,在管理的角度来看,人们不太清楚服务器之间的区别
- 您可以使用
include
指令将每个服务器分离到一个单独的文件中。这样,任何查看您的设置的人都可以很容易地使用来清楚地看到服务器之间的区别,您也可以对其中一个服务器文件进行更改,然后将所述更改应用于其他服务器,这也让我们找到了根本原因
- 您可以使用
include
将每个server
中所有相同的部分放在一个给定的文件中,其中每个server
将非常简单,并且只列出配置之间的实际差异
- 您可以使用变量来分离传递给某些指令的值。请注意,直接在
if
中使用各种指令通常不起作用,但使用中间变量可以实现同样的效果
组合包括
和设置
- 考虑到未来的发展计划,您可能应该结合上述想法来满足您的确切需求
如何有条件地使用set
?
如果您希望在一台服务器中安装整个内容,可以有条件地使用设置:
set $mage_rc "default";
if ($server_name = test1.com) {
set $mage_rc "test1";
}
location ~ \.php$ {
…
fastcgi_param MAGE_RUN_CODE $mage_rc;
…
}
那么,我从哪里开始呢?
根据您提供的信息,我可能会将服务器分开(即仍然使用单独的服务器
指令),在每个服务器
中定义一些局部变量,并且包括两个服务器的公共配置,其中在所述公共配置中使用变量,如$mage_rc
,从每个服务器中定义开始,应继续执行。使用单独的服务器
s,如果
如上所述,则无需使用——只需在每个服务器
中单独定义每个变量,一次用于整个服务器
上下文