进入/usr/local/nginx/conf

编辑 nginx.conf
绑定域名:
添加一个 server元素,更改后的配置内容可能如下:
server
{
listen       80;
server_name xmdm.easymobi.cn;
index index.html index.htm index.php;
root  /home/wwwroot;
location ~ .*\.(php|php5)?$
{
fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location /status {
stub_status on;
access_log   off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires      30d;
}
location ~ .*\.(js|css)?$
{
expires      12h;
}
log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
access_log  /home/wwwlogs/xmdm.log  access;
}
这里,就将域名:xmdm.easymobi.cn 绑定到该机器上.如果要绑定另外一个,则再添加一个server.
添加自己的 server 时要注意的是:log_format access 后的格式不能是一样。不然会报错。
 
url - rewrite:
经常看到如下链接:
http://www.ssss.com/3/4/cmd
这个 http 请求经过 web 服务器时,会被rewrite 规则解析成另一个地址,如:http://www.ssss.com/index.php?a=3&b=4&c=cmd
如果没有定义rewrite规则,上面的地址肯定就无法找到了。
nginx的定义方法和apache的非常相似,如下:
location / {
rewrite ^/category/(\d+)/(.+)/(\d+)$ /category.php?cateId=$1&nowPage=$3 last;
rewrite ^/detail/(\d+)/(.+)$ /detail.php?id=$1 last;
rewrite ^/result/(.+)/(\d+)/(\d+)$ /result.php?keyword=$1&id=$2&nowPage=$3 last;
rewrite ^/result/(\d+)/(\d+)$ /result.php?id=$1&nowPage=$2 last;
}
location / 表示访问域名根目录下的地址
下面rewrite 后有两个正则表达式,前面一个是用户输入的地址;后面是要转义成的。
编辑完成后,需要重新加载 nginx:
进入usr/local/nginx/sbin
执行: ./nginx -s reload
 
下面贴一个 apache 下的设置方式:
<IfModule mod_rewrite.c>
RewriteEngine on 
RewriteRule ^/?category/(\d+)/(.+)/(\d+)$ category.php?cateId=$1&nowPage=$3 [L]
RewriteRule ^/?detail/(\d+)/(.+)$ detail.php?id=$1 [L]
RewriteRule ^/?result/(.+)/(\d+)/(\d+)$ result.php?keyword=$1&id=$2&nowPage=$3 [L]
RewriteRule ^/?result/(\d+)/(\d+)$ result.php?id=$1&nowPage=$2 [L]
</IfModule>
这一段我是放在 .htaccess 中的。

Linux--nginx域名绑定-url rewrite的更多相关文章

  1. nginx 域名绑定端

    server { listen 80; server_name taqing.me www.taqing.me; ##,绑定域名 location / { proxy_pass http://127. ...

  2. nginx 域名绑定 域名, nginx 域名绑定 端口

    一.nginx 域名绑定 域名 nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件 ...

  3. nginx 域名绑定

    单个域名 upstream web{ server ;//这里绑定你要访问的服务器地址 keepalive ; } server { listen ; server_name www.xxxx.con ...

  4. [转]nginx下的url rewrite

    转:http://zhengdl126.iteye.com/blog/698206 if (!-e $request_filename){rewrite "^/index\.html&quo ...

  5. 5G时代,URL Rewrite 还吃香吗

    URL Rewrite是网站建设中经常用到的一项技巧,通过 rewrite 我们能够屏蔽服务器运行态的信息,包括服务的程序.参数等等,给用户呈现美化后的URL,同时对搜索引擎更加友好,方便我们网站的推 ...

  6. linux nginx不区别大小写处理方法

    # 把所有的目录及文件名全改成小写,注意之后新增目录及文件只使用小写命名 递归转换目录或文件名方法:python把指定目录下的递归所有目录和文件名转换成小写或大写(http://www.cnblogs ...

  7. 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定

    阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...

  8. nginx 多域名配置 (nginx如何绑定多个域名)

         nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里. 一.每个域名一个 ...

  9. 服务器 nginx配置 防止其他域名绑定自己的服务器

    基于我的网站被其他的域名恶意绑定了,我做出了如下处理,全站转https,同时配置nginx跳转禁止其他绑定ip的域名访问(原理主机空域名可绑定任意的,参考https://www.jb51.net/ar ...

随机推荐

  1. MATLAB 2016b 切换回英文版

    原因: 中文下不能使用等间距字体.因为等间距字体都是英文字体,报错信息又是中文的,所以这时候报错就全是乱码.如果改成中文字体,又不是等间距的了,看着瞎眼. 方法: Preferences->Ge ...

  2. LeetCode: Add Two Numbers 解题报告

    Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are ...

  3. How To Install Java with Apt-Get on Ubuntu 16.04

    Introduction Java and the JVM (Java's virtual machine) are widely used and required for many kinds o ...

  4. [转载]生活在 Emacs 中

    Brian Bilbrey2002 年 8 月 20 日发布 教程简介 本教程讲什么? Emacs 是一个流行的无模式文本编辑器,有许多强大的功能.本教程将教您使用 Emacs 的基础知识.为了让您很 ...

  5. Spring事务管理要点总结

    # Spring事务管理要点总结 ### 要点---- 事务是企业级应用中必不可缺少的技术,用来确保数据的完整性和一致性.- Spring事务管理并不实现事务管理的实现,而是借助Hibernate\J ...

  6. JAVA-JSP内置对象之application对象获得服务器版本

    相关资料:<21天学通Java Web开发> application对象获得服务器版本1.通过application对象的getMajorVersion()方法和getMinorVersi ...

  7. A. Counterexample (Codeforces Round #275(div2)

    A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. highcharts图表组件通过设置tooltip属性自定义数据提示信息

    我们先来看看这样一个例子,全局配置好tooltip,数据点的提示信息能够自己根据数据点自身数据情况加以显示,代码如下所示: 01.$(function () { 02.$('#container'). ...

  9. 【Web】关于Session过期/失效的理解

    一直好奇关于Session的过期,一种说法是关闭浏览器即Session失效,另一种说法是可以设置Session的过期时间,时间到了自动过期. 这两种说法到底是怎么回事?Session过期跟Cookie ...

  10. C#中的volatile关键字

    volatile 关键字指示一个字段可以由多个同时执行的线程修改. 声明为 volatile 的字段不受编译器优化(假定由单个线程访问)的限制. 这样可以确保该字段在任何时间呈现的都是最新的值. vo ...