nginx反向代理服务器域名解析配置

操作系统:mint17.2

1.进入cd /opt/nginx/conf

2.sudo mkdir vhost

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

include vhost/*.conf;//添加这条语句

# HTTPS server 

4.因为是内网模拟,编辑/etc/hosts,配置

192.168.3.9  www.fruit.com

192.168.3.9 image.fruit.com

192.168.3.9  s.fruit.com

5.进入vhost里面

cd /opt/nginx/conf/vhost

6.在vhost里面创建文件

sudo gedit www.fruit.com.conf

里面的内容如下:

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

访问:www.fruit.com则访问到tomcat(域名转发的一种)

8.在vhost里面创建文件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端口

你可能感兴趣的:(nginx反向代理服务器域名解析配置)