1. 程式人生 > >nginx反向代理服務器域名解析配置實操

nginx反向代理服務器域名解析配置實操

urn pos learn server pro 域名解析 實操 post type

1、進入nginx目錄cd conf:創建文件夾

sudo mkdir vhost,cd vhost,sudo vim www.fanxing.store.conf,添加如下內容

server {
default_type ‘text/html‘;
charset utf-8;
listen 80;
autoindex on;
server_name www.fanxing.store;
access_log /usr/local/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 /product/ftpfile/learning/;

proxy_pass http://127.0.0.1:8080; //暫時跳到tomcat
add_header Access-Control-Allow-Origin *;
}
}

保存

2.重啟nginx:sudo ../../sbin/nginx -s rload

3.配置文件服務器

server {
listen 80;
autoindex off;
server_name image.fanxing.store;
access_log /usr/local/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 *;
}
}

*****出現404Not Found:image.fanxing.store末尾未加.conf,如果未配置,默認加載nginx/下的nginx.conf

(nginx: [warn] conflicting server name "image.fanxing.store" on 0.0.0.0:80, ignored,)

nginx -s reload

重啟nginx報錯。

[warn]: conflicting server name “domain.com” on 0.0.0.0:80, ignored

檢查:server/nginx-1.4.7/conf/vhosts 下的配置文件,應該有重復綁定域名的,找到,修改或刪除即可。

如果image.fanxing.store.conf:autoindex off;就無法訪問目錄結構,出現403forbidden錯誤,不可訪問;

*******

nginx反向代理服務器域名解析配置實操