阿里雲配置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

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