nginx反向代理服務(wù)器域名解析配置

操作系統(tǒng):mint17.2

1.進(jìn)入cd /opt/nginx/conf

2.sudo mkdir vhost

3.修改nginx配置文件,sudo gedit nginx.conf

include vhost/*.conf;//添加這條語(yǔ)句

# HTTPS server?

4.因?yàn)槭莾?nèi)網(wǎng)模擬,編輯/etc/hosts,配置

192.168.3.9? www.fruit.com

192.168.3.9 image.fruit.com

192.168.3.9? s.fruit.com

5.進(jìn)入vhost里面

cd /opt/nginx/conf/vhost

6.在vhost里面創(chuàng)建文件

sudo gedit www.fruit.com.conf

里面的內(nèi)容如下:

server {

listen 80;

autoindex on;

server_name www.fruit.com;

access_log /opt/nginx/logs/access.log combined;

index index.html index.htm index.jsp index.php;

#error_page 404 /404.html;

if ( $query_string ~* ".*[\;'\<\>].*" ){

return 404;

}

location / {

proxy_pass http://127.0.0.1:8080;

add_header Access-Control-Allow-Origin *;

}

}

7.重啟nginx

用nginx -c指定配置文件位置

sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

sudo /opt/nginx/sbin/nginx -s reload 重啟nginx

訪問(wèn):www.fruit.com則訪問(wèn)到tomcat(域名轉(zhuǎn)發(fā)的一種)

8.在vhost里面創(chuàng)建文件image.fruit.com.conf

server {

listen 80;

autoindex off;

server_name image.fruit.com;

access_log /opt/nginx/logs/access.log combined;

index index.html index.htm index.jsp index.php;

#error_page 404 /404.html;

if ( $query_string ~* ".*[\;'\<\>].*" ){

return 404;

}

location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {

deny all;

}

location / {

root /ftpfile/;

add_header Access-Control-Allow-Origin *;

}

}


重啟nginx(域名映射到文件夾)

sudo /opt/nginx/sbin/nginx -s reload

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT防火墻打開80端口

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容