nginx unified domain approach

2010-09-09  来源:本站原创  分类:Ruby  人气:167 

Requirements: test.com will be redirected to www.test.com, empathy test.com/post/1 will be redirected to the www.test.com/post/1

last - basically using the Flag
break - stop Rewrite, not to match
redirect - return to temporary redirect HTTP status 302
permanent - permanent redirect HTTP status returned 301

To achieve a

Modify nginx.conf file, as follows:

# Only test.com Steering  www.test.com
server {
  listen 80;
  server_name test.com;
  access_log off;
  rewrite ^ http://www.test.com$request_uri permanent;
}

#www.test.com Main configuration
server {
  listen 80:
  server_name www.test.com;
  # Configuring content  ...
}

Be a better method.

Advantage
Only when the only access test.com redirected to www.test.com.
Access www.test.com from server test.com rewrite of.

<br /> Use to the disadvantage of the two server ()

Implementation II

Modify nginx.conf file, as follows:

server{
  listen 80;
  server_name test.com www.test.com
  if ($host != 'www.test.com) {
    rewrite ^/(.*)$ http://www.test.com/$1 permanent;
  }
}

Advantages of a server () <br /> resolved

Shortcoming
Whether access test.com or www.test.com, each client must be a nginx if () the judge, access domain name is not www.test.com, more waste of resources.

相关文章
  • nginx unified domain approach 2010-09-09

    Requirements: test.com will be redirected to www.test.com, empathy test.com/post/1 will be redirected to the www.test.com/post/1 last - basically using the Flag break - stop Rewrite, not to match redirect - return to temporary redirect HTTP status 30

  • nginx secondary domain name matches the root directory of the sub-folders 2010-05-24

    Binding domain server_name *. abcd.com; Get host name if ($ host ~ * (.*) \ .(.*) \ .(.*)) ( set $ domain $ 1; ) Definition List root html / abc / $ domain /; location / ( root html / abcd / $ domain; index index.html index.php; ) -------------------

  • Tomcat5.5 while multi domain approach access to the same ip. 2010-05-15

    In server.xml, the port to 80, the other configuration example is as follows. <Engine name = "Catalina" defaultHost = " www.aaa.com "> <Realm className = "org.apache.catalina.realm.UserDatabaseRealm" resourceName = &

  • apache server platform with lighttpd.nginx analysis of the three WEB 2009-12-15

    This did not include the IIS server, which, because IIS can only run on Windows, but apache and lighttpd, nginx three WEB Web server can be run on various platforms. See the following article analysis: 1. Software Description (apache lighttpd nginx)

  • Internet Explorer, at the same time can only download two files from the same domain name 2010-03-25

    For reasons, see MSDN Blogs: " Internet Explorer and Connection Limits ", how to lift the restrictions, see Microsoft customer help and support page:" How to configure Internet Explorer can download more than two simultaneous sessions . &qu

  • Remember my first configure Apache server domain name resolution and domain name resolution process of the Pan- 2010-03-31

    Configuring apache for multiple domain name resolution, need to use the following things: C: \ WINDOWS \ system32 \ drivers \ etc \ hosts (DNS domain name resolution files) Apache2.2.11 \ conf \ httpd.conf Apache2.2.11 \ conf \ extra \ httpd-vhosts.c

  • Tomcat5.5 configuration - more binding domain and virtual directory 2010-04-28

    tomcat with the default installation, to tamcat direct binding multiple domain names, where we need to modify the configuration file: C: \ Program Files \ Apache Software Foundation \ Tomcat 5.5 \ conf \ server.xml server.xml changes as follows: (A)

  • apache lighttpd nginx 2010-12-04

    One. Software (apache lighttpd nginx) 1. Lighttpd Lighttpd is a very low memory footprint, cpu occupancy rate is low, performance is good, and a wealth of modules and so on. lighttpd is a lightweight web server OpenSource many of the more outstanding

  • Turn: ubuntu 32 to manually install nginx 2011-06-01

    Originally Posted http://sudone.com/nginx/nginx_new_install.html Generally compile nginx, we need to first install the pcre, zlib and other external support programs, then compile and install nginx specified when the location of these external suppor

  • php管理nginx虚拟主机shell脚本实例 2014-07-24

    这篇文章主要介绍了php管理nginx虚拟主机shell脚本的实现方法,以实例形式讲述了通过PHP脚本管理nginx虚拟主机的方法,具有不错的借鉴价值,需要的朋友可以参考下 本文实例讲述了php管理nginx虚拟主机shell脚本,分享给大家供大家参考.具体分析如下: 使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考: #!/usr/bin/php -q <?php start: fwrite(STDO

  • Nginx 虚拟主机 配置 支持独立urlwrite 文件, php-fpm独立用户和php.... 2011-09-23

    Nginx 虚拟主机 环境配置. 最近租了台服务器,准备做一些网站.纠结apache/nginx很久,最后选定了Nginx+php-fpm. 因为可能会有几个站,为了安全,我希望每个站点直接都能尽量独立,避免互相影响. 主要实现功能: -能够相对快捷的添加虚拟主机. -每个虚拟主机直接相对独立,避免一个网站有漏洞,全服务器手影响 -能够方便的配置urlrewrite,还是需要reload或restart ( 谁让nginx 不支持像 .htaccess 这样吗方便的东西呢?) -每个虚拟主机能独

  • Using Microsoft Active Directory (AD) solutions, IT staff can support a Lapp Cable (Shanghai) Co., Ltd. National channels 2009-08-14

    Lapp Cable (Shanghai) Co., Ltd. is one of the world leaders in the cable industry, cable companies Cable & P Co., Ltd. a wholly owned subsidiary in China, Lapp Cable Co., Ltd. is an industrial control world's first inventor of the cable, over the yea

  • ROR of the Chinese question 2010-08-24

    Environment: os: ubuntu 10.04 ruby: 1.9.2 rails: rails3 server: webrick / nginx + passenger Brought before the procedure to run when I discover there are Chinese in ruby ah! In theory, the character encoding is UTF-8 and should not be a problem, at l

  • ROR + mysql problems in Chinese 2010-08-24

    Environment: os: ubuntu 10.04 ruby: 1.9.2 rails: rails3 server: webrick / nginx + passenger Brought before the procedure to run when I discover there are Chinese in ruby ah! In theory, the character encoding is UTF-8 and should not be a problem, at l

  • js form validation Guinness 2009-03-03

    js form validation Guinness 1. Length <script> function test () ( if (document.abvalue.length> 50) ( alert ( "Can not more than 50 characters!"); document.abfocus (); return false; ) ) </ script> <form name=a onsubmit="ret

  • Zhang feast an alternative AJAX cross-domain solutions 2009-04-08

    Zhang feast today to see a reference to the use of flash interim cross-domain AJAX requests to do an alternative solution, quite new and novel, click Record. The following content was reproduced Zhang BLOG feast on the article [Article + some code Au

  • js form validation control code Guinness 2009-09-26

    Keyword: js form validation Book, using JS to control form submission, javascript submit form: Contents: 1: js string length to determine the length of characters, js restrict the importation, restrictions can not be imported, textarea length limit 2

  • Flex and AS3 Common Knowledge of 100 2008-10-05

    【Change the output swf scale, background color, or frame rate】 In the "Navigator" window frame right inside your project "select" Properties "> select" ActionScript Compiler "> in the" Additional compiler argu

  • The role and benefits of SSH levels (personal collection, You Dianjiu) 2008-10-11

    Simply put: struts controlling the hibernate operation of the database spring with a detailed decoupling said: struts in the SSH framework of the play the role of the control of its core is Controller, that is ActionServlet, the ActionServlet is the

  • Flex some of the common methods 2010-05-13

    Although the Action Script syntax for people who are not hard to learn Java, but after all, there are differences between the two, and use by java is not working sometimes rigidly, so look for the article to reference. Original Address:: http://blog.