【问题标题】:Proper deployment of multiple sites using Nginx使用 Nginx 正确部署多个站点
【发布时间】:2014-09-05 16:43:52
【问题描述】:

我是服务器的业余爱好者,我正在本地 ubuntu 机器上设置 Nginx。我有多个站点并在本地工作,作为转移到实时服务器的练习。我不确定这是否是相关网站的最佳设置。它们是 wordpress 网站。

每个站点文件夹都在var/www

/var/www/site1
/var/www/site2

我将/etc/nginx/sites-available/default 中的默认文件链接到/etc/nginx/sites-enabled/default。保持原样。特别注意听的部分;

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

使用这个文件作为基础,我对两个站点都做了同样的事情,为每个可用站点创建单独的文件,并将它们链接到启用的站点。这是site1s设置;

server {
        listen 80;
        listen [::]:80;

        root /var/www/site1;
        index index.php index.html index.htm;

        server_name local.site1.com; #for testing, edited in hosts

        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

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

我的问题很简单;这是设置 Nginx 服务器的有效方法吗? This 线程将我的设置列为一个选项,但没有任何关于它的效率。我将启用站点的默认设置为“default_server”,而我的实际站点只是监听端口 80;我对端口不是很了解..

我现在想询问是否为每个站点设置一个“专用”数据库服务器(块),但也许这是一个完全不同的鱼锅..

【问题讨论】:

  • 你担心什么样的效率?
  • 我听说 Nginx 可以根据需求进行扩展(与 Apache 不同),但我不知道是否有任何特殊配置可以启用此功能,或者它是否默认“工作”
  • Nginx 和 Apache 都不能自动扩展任何东西……因为你通常谈论的是多台服务器和其他完全不同的东西。 Nginx 拥有比 Apache 更高效的线程模型,这可能是你听说过的。而且,由于这与 Nginx 的设计方式而不是配置有关,因此它确实可以工作。

标签: ubuntu nginx


【解决方案1】:

您的配置没问题,只需使用包含,您可以从 1 个文件更改所有站点的全局参数。

site1s.conf:

server {
   root /var/www/site1;
   server_name local.site1.com; #for testing, edited in hosts

   include /etc/nginx/conf.d/global.cnf;
}

site2s.conf ... siteNs.conf 从 site1s.conf 克隆(您只需更改 2 行主机名)

/etc/nginx/conf.d/global.cnf(或任何您喜欢的名称,但最好不要使用 .conf 扩展名,以避免 nginx 自动加载 - 我不知道您的所有配置):

listen 80;
listen [::]:80;

index index.php index.html index.htm;

location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
        root /usr/share/nginx/html;
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多