Nginx在只有一个域名的情况下开启另外一个网站
由于我目前只有一个域名,网站放在/home/www/下,一个网站一个目录,现在想将其中a网站访问形式为http://www.6688.cc,想让另一个与a处于同一目录下的b网站用http://www.6688.cc/b/的形式访问,总结如下:
1.修改/usr/local/etc/apache22/extra/http-vhost.conf
<VirtualHost *:81>
ServerAdmin [email protected]
DocumentRoot "/home/www/a"
ServerName www.6688.cc
ErrorLog "/var/log/www.6688.cc-error_log"
CustomLog "/var/log/www.6688.cc-access_log" common
<Directory "/home/www/a">
Options none
AllowOverride none
Order Allow,deny
Allow from all
</Directory>
Alias /phpmyadmin/ "/home/www/phpMyAdmin/"
<Directory "/home/www/phpMyAdmin">
Options none
AllowOverride none
Order Allow,deny
Allow from all
</Directory>
Alias /rdya/ "/home/www/b/"
<Directory "/home/www/b">
Options none
AllowOverride none
Order Allow,deny
Allow from all
</Directory>
</VirtualHost>
2.修改/usr/local/etc/nginx/nginx.conf
server {
listen 80;
server_name rd.jinchang.gov.cn;
charset gbk;
client_max_body_size 100m;
#access_log logs/host.access.log main;
location / {
root /home/www/a;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
proxy_pass http://192.168.1.13:81;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /b/ {
alias /home/www/b/;
index index.php;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
3.重启apache,nginx