在ubuntu利用nginx反响代理在一个端口下配置多个站点
在一个服务器下,暂时没有域名,多域名很容易这里不做过多的说明。
一台服务器的 ip如下:192.168.1.101 默认的niginx 80端口。项目目录在/var/www/html 下 我们新建另一个项目目录 在/var/www/wecaht
若果我们访问192.168.1.101/wechat 需要配置如下:
我还是需要另一个端口 比如8001 在/etc/nginx/sites-available 下新建配置文件 wechat
listen 8001;
server_name wechat.com;
root /var/www/wechat;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location ~* \.(eot|otf|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
ln -s /etc/nginx /sites-available /etc/nginx/sites-enable/wechat
创建软连接
保存推出 service nginx restart
访问192.168.1.101:8001 我们将访问 wechat 目录的php项目
现在我们在 默认配置文件 /etc/nginx /sites-available/default 增加反向代理
location /wechat/ {
proxy_pass http://192.168.1.101:8001;
}
然后重启 nginx 服务器
访问 http://192.168.1.101/wechat 就ok了