简洁的想法

 找回密码
 注册
搜索
查看: 502|回复: 0

Nginx的泛域名绑定

[复制链接]
发表于 2011-10-5 10:30:54 | 显示全部楼层 |阅读模式
这阵子在折腾nginx的web服务器,自从看见网上有些老大讲nginx的性能N好,所以这两天在搞搞了,不过最想研究的就是nginx的泛域名绑定,因为现在用的lighttpd服务器上也搞了个这样的设置,当然,一切操作都在VMware的虚拟机内搞了,一直觉得Vmware虚拟机是个伟大的发明.

不过经过今天一天在虚拟机的研究,终于搞好了,系统环境是Debian 4的Linux, PHP Version 5.2.6, Nginx0.6.32手工编译,还有lighttpd-1.4-19编译的spawn-fcgi 。

效果:

http://www.lpfrx.com => /var/www/lpfrx.com/www
http://xxx.lpfrx.com => /var/www/lpfrx.com/xxx
http://192.168.0.100 => /var/www/0.100/192.168

nginx.conf :
  1.     #user nobody;
  2.     user www-data;
  3.     worker_processes 1;

  4.     #error_log logs/error.log;
  5.     #error_log logs/error.log notice;
  6.     #error_log logs/error.log info;

  7.     #pid logs/nginx.pid;

  8.     events {
  9.     worker_connections 1024;
  10.     }

  11.     http {
  12.     include mime.types;
  13.     default_type application/octet-stream;

  14.     #log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
  15.     # ‘”$status” $body_bytes_sent “$http_referer” ‘
  16.     # ‘”$http_user_agent” “$http_x_forwarded_for”‘;

  17.     #access_log logs/access.log main;

  18.     sendfile on;
  19.     #tcp_nopush on;

  20.     #keepalive_timeout 0;
  21.     keepalive_timeout 65;

  22.     #gzip on;

  23.     server {

  24.     listen 80;
  25.     #server_name localhost;
  26.     server_name _;
  27.     #charset koi8-r;

  28.     set $hostx $host;

  29.     #access_log logs/host.access.log main;

  30.     if ( $host ~* (.*)\.(.*)\.(.*) ) {

  31.     set $hostx $2.$3/$1;

  32.     }

  33.     location / {
  34.     #root html;
  35.     root /var/www/$hostx;
  36.     index index.php index.html index.htm;

  37.     if (-d $request_filename)
  38.     {

  39.     rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

  40.     }

  41.     # wordpress rewrite
  42.     if (-f $request_filename/index.php){
  43.     rewrite ^/wordpress/(.*) /wordpress/$1/index.php;
  44.     }
  45.     if (!-f $request_filename){
  46.     rewrite ^/wordpress/(.*) /wordpress/index.php;
  47.     }

  48.     }

  49.     #error_page 404 /404.html;

  50.     # redirect server error pages to the static page /50x.html
  51.     #
  52.     error_page 500 502 503 504 /50x.html;
  53.     location = /50x.html {
  54.     root html;
  55.     }

  56.     # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  57.     #
  58.     #location ~ \.php$ {
  59.     # proxy_pass http://127.0.0.1;
  60.     #}

  61.     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  62.     #
  63.     location ~ \.php$ {
  64.     # root html;
  65.     fastcgi_pass 127.0.0.1:9000;
  66.     fastcgi_index index.php;
  67.     fastcgi_param SCRIPT_FILENAME /var/www/$hostx/$fastcgi_script_name;
  68.     include /usr/local/nginx/conf/fastcgi_params;
  69.     }

  70.     # deny access to .htaccess files, if Apache’s document root
  71.     # concurs with nginx’s one
  72.     #

  73.     location ~ /\.ht {
  74.     deny all;
  75.     }
  76.     }

  77.     # another virtual host using mix of IP-, name-, and port-based configuration
  78.     #
  79.     #server {
  80.     # listen 8000;
  81.     # listen somename:8080;
  82.     # server_name somename alias another.alias;

  83.     # location / {
  84.     # root html;
  85.     # index index.html index.htm;
  86.     # }
  87.     #}

  88.     # HTTPS server
  89.     #
  90.     #server {
  91.     # listen 443;
  92.     # server_name localhost;

  93.     # ssl on;
  94.     # ssl_certificate cert.pem;
  95.     # ssl_certificate_key cert.key;

  96.     # ssl_session_timeout 5m;

  97.     # ssl_protocols SSLv2 SSLv3 TLSv1;
  98.     # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  99.     # ssl_prefer_server_ciphers on;

  100.     # location / {
  101.     # root html;
  102.     # index index.html index.htm;
  103.     # }
  104.     #}

  105.     }
复制代码
然后启动nginx就可以实现了.
达到了预期的效果,而且也装了个wordpress的blog测试了永久链接的rewrite的功能, 等研究搞掂perl在nginx的应用后再迁移lighttpd的web服务器到nginx去.

转自:http://www.lpfrx.com/archives/105/
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|Archiver|简洁的想法

GMT+1, 2021-3-9 03:00

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表