阿里云配置nginx多域名指向

我的阿里云默认在服务器的/alidata/server/nginx中;

因为nginx中的conf文件夹中的nginx.conf文件配置默认指向的是vhosts文件夹下的所有*.conf文件都有效,所有只要复制default.conf文件,并且修改文件中的内容即可,具体内容如下:
1、到/alidata/server/nginx/conf/vhosts文件夹下
cd /alidata/server/nginx/conf/vhosts
2、复制default.conf文件,并且命名成一个新的文件,如域名.conf
cp default.conf aaa.conf
如果是文件夹入职的话用cp -r a b
3、打开aaa.conf文件并且修改里面的内容
vi aaa.conf
listen为外部端口所以不变;server_name 为域名;root 为项目绝对路径; location后面改成“/”即所有的文件;proxy_pass即tomcat启动之后的项目访问路径;
如下:
server {
listen 80;
server_name aaa.com www.aaa.com;
charset utf-8;
index index.html index.htm index.jsp;
root /alidata/server/tomcat7/webapps/AAA;

location / {
proxy_pass http://127.0.0.1:8080/AAA/;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 1h;
}

access_log /alidata/log/nginx/access/default.log;
}

退出编辑器 按Esc :wq 保存并退出

4、保存完毕之后验证配置文件修改是否正确
/alidata/server/nginx/sbin/nginx -t
如果配置文件不正确,屏幕会提示配置文件的第几行出错:

nginx:[emerg] invalid number of arguments in “autoindex” directive in /usr/local/nginx/conf/nginx.conf:29

nginx:configuration file /usr/local/nginx/conf/nginx.conf test failed

如果配置文件正确,屏幕将提示以下两行信息:

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

configuration file /usr/local/nginx/conf/nginx.conf test is successful

5、如果配置正确就重启
/alidata/server/nginx/sbin/nginx -s reload

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章