进入/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. jdango 部署之nginx+uwsgi

    1,安装pip sudo apt-get install python-pip 2,利用 pip 安装 Django sudo pip install Django 3,检测Django是否安装成功 ...

  2. js设置滚动条定位到所属容器的最底部

    $('.help-gundongtiao').scrollTop($('.help-gundongtiao')[0].scrollHeight);

  3. Python3下requests库发送multipart/form-data类型请求

    [本文出自天外归云的博客园] 要模拟multipart/form-data类型请求,可以用python3的requests库完成.代码示例如下: #请求的接口url url = "url&q ...

  4. JAVA-JSP内置对象之pageContext对象取得不同范围属性

    相关资料:<21天学通Java Web开发> pageContext对象取得不同范围属性 pageContextDemo.jsp <%@ page language="ja ...

  5. 基于jquery hover图片遮罩层滑动

    分享一款基于jquery hover图片遮罩层滑动.这是一款仿腾讯课堂的鼠标悬停经过图片遮罩透明层滑动效果.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div clas ...

  6. 【转】eclipse运行 Ant报错Could not find the main class: org.eclipse.ant.internal.launching.remote.InternalAntRunner. Program

    原文地址:http://blog.csdn.net/jiangtaoking/article/details/49151763 Could not find the main class: org.e ...

  7. mac OS X中升级php5.5至php5.6 or php7

    在做php项目中,提示“Warning. PHP 5.6 or newer is required. Please, upgrade your local PHP installation.” 通过p ...

  8. wamp升级php5.3.10到php5.6.13版本

    1.  停止WAMP服务器. 2.  去网站windows.php.net 下载php-5.6.13-nts-Win32-VC9-x86.zip. 不要下载THE INSTALLER. 3.  在wa ...

  9. 首部讲Python爬虫电子书 Web Scraping with Python

    首部python爬虫的电子书2015.6pdf<web scraping with python> http://pan.baidu.com/s/1jGL625g 可直接下载 waterm ...

  10. C# BCC异或校验法

    通讯协议中最后一位是校验位 采用BCC(异或校验)法 这个怎么解释? 就是 把16进制的字符串转换成byte[]数据,依次拿出来进行异或一下 然后返回的值和校验位对比下 看看对不对 例如: 23230 ...