Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx配置学习篇 #20

Open
fredshare opened this issue Feb 2, 2015 · 0 comments
Open

nginx配置学习篇 #20

fredshare opened this issue Feb 2, 2015 · 0 comments
Labels

Comments

@fredshare
Copy link
Owner

nginx配置学习篇

最近需要对网站的nginx进行配置,学习了下相关的知识。
需要解决的问题:

没有www的域名test.com指向到www.test.com
移动端自动指向到m.test.com上,pc上访问自动指向到www.test.com

对于第一个问题:

域名提供商管理页面进行相关配置,新增一个域名解析记录,记录类型为A记录,意思是说当用户输入test,com时候将转到ip为xx.xx.xx.xx的机器

image

设置相关机器的nginx配置,新增一条server记录

一般nginx的配置都在/usr/local/nginx/conf/

server {
    server_name test.com;
    rewrite ^/(.*)$ http://www.test.com/home_page permanent;
    root   html;
    index  index.html index.htm;
}

对于第二个问题:

server {
    server_name test.com;
    if ( $http_user_agent ~* "(Android|webOS|iPhone|iPod|BlackBerry)" ) {
            rewrite ^/(.*)$ http://mobile.test.com/home_page permanent;
    }
    rewrite ^/(.*)$ http://www.test.com/home_page permanent;
    root   html;
    index  index.html index.htm;
}
@fredshare fredshare added the blog label Feb 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant