Nginx反向代理服务器安装与配置

一.服务器安装:

sudo yum install gcc-c++
sudo yum install pcre pcre-devel
sudo yum install zlib zlib-devel
sudo yum install openssl openssl-devel

备注:ps aux是显示所有进程和其状态。

访问:http://39.108.63.239

到此安装成功。

 

二.配置:

 首先需要配置hosts域名和ip映射:

 

 

加上这一句:

 

以下配置hosts应该是不需要的(因为我是在windows的浏览器访问的):

 

修改成如下(按照实际情况):

 

加上:

server {       
 default_type 'text/html';       
 charset utf-8;       
 listen 80;       
 autoindex on;       
 server_name www.ouyan.com;                
 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 / {                
    proxy_pass http://127.0.0.1:8080;
    add_header Access-Control-Allow-Origin *;
        }
}

然后访问即可。

接下来看第二种配置(以下两个命令可以合二为一):

server {
listen 80;
autoindex off;
server_name image.ouyan.com;
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 *;
}
}

然后访问即可。

注意:该配置是在虚拟机下的配置,实际在线上的配置后续再说。

posted @ 2018-01-02 17:15  虚极静笃  Views(188)  Comments(0Edit  收藏  举报