xuanhao 发表于 2018-11-13 12:28:10

Linux系统 nginx伪静态配置及nginx重启

  用nginx创建了一下站点!安装了dzx1
  方法如下:
  1. 在需要使用.htaccess文件的目录下新建一个.htaccess文件,
  如本人的一个Discuz论坛目录:
  vim /opt/wwwroot/discuz/.htaccess
  2. 在里面输入规则,我这里输入Discuz的伪静态规则:
  # nginx rewrite rule
  rewrite ^(.*)/archiver/((fid|tid)-+.html)$ $1/archiver/index.php?$2 last;
  rewrite ^(.*)/forum-(+)-(+).html$ $1/forumdisplay.php?fid=$2&page=$3 last;
  rewrite ^(.*)/thread-(+)-(+)-(+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last;
  rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last;
  rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last;
  rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last;
  # end nginx rewrite rule
  wq保存退出。
  注意一下:在这里规则按照上面写就可以的!当然rewrite不能为大写
  3. 修改nginx配置文件:
  vim /usr/local/webserver/nginx/conf/nginx.conf
  4. 在需要添加伪静态的虚拟主机的server{}中引入.htaccess文件,
  server
  {
  listen 80;
  server_namewww.101tao.com;
  access_log /opt/logs/aa.log;
  root /opt/wwwroot/discuz;
  location /
  {
  index index.html index.htm index.php;
  }
  include /opt/wwwroot/discuz/.htaccess;
  location ~ .*\.(php|php5)?$
  {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi.conf;
  }
  }
  wq保存退出。
  5. 重新加载nginx配置文件:
  重新打开网页看看,如果伪静态正常就证明你的rewrite rule语法是正确的。
  重启nginx命令:
  经常需要重启nginx,但网上的很多教程都需要繁琐的启动脚本,远不如apache的重启命令那么简单。
  但研究了一下nginx帮助后发现,有-s参数可对nginx服务进行管理:
  # /usr/local/nginx/sbin/nginx -h
  nginx version: nginx/0.7.63
  Usage: nginx [-?hvVt] [-s signal] [-c filename] [-p prefix] [-g directives]
  Options:
  -?,-h : this help
  -v : show version and exit
  -V : show version and configure options then exit
  -t : test configuration and exit

  -s signal : send signal to a master process: stop, quit, reopen,>  -p prefix : set prefix path (default: /usr/local/nginx/)
  -c filename : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
  于是我执行

  # /usr/local/nginx/sbin/nginx-s>  nginx已经重启成功
  Nginx由于没有免费的控制面板支持,所以需要修改 /usr/local/nginx/conf/nginx.conf 这个文件来实现服务器性能、特性的配置。
  上传下载配置文件建议使用Winscp这个工具,同样基于SSH协议,比Ftp安全。
  在 http://wiki.nginx.org/NginxConfiguration 有很多配置文件的文档和例子。
  默认的配置文件也不错,有以下几点需要注意:
  每次修改配置文件并上传后,需要测试配置文件是否正确,命令如下:
  /usr/local/nginx/sbin/nginx -t
  修改配置后,必须重启Nginx才能生效,Nginx进程无缝重启命令如下:
  kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

页: [1]
查看完整版本: Linux系统 nginx伪静态配置及nginx重启