nginx反向代理服务器搭建

共1625个字

环境:
ubuntu 16.04.3 LTS
ginx version: nginx/1.10.3 (Ubuntu)
 

注:本文仅涉及反向代理,不对负载均衡功能做描述。

目录
root@ubuntu:cd /etc/nginx

conf.d          koi-utf     nginx.conf    sites-available  uwsgi_params

fastcgi.conf    koi-win     proxy_params  sites-enabled    win-utf

fastcgi_params  mime.types  scgi_params   snippets 


删除掉原来在
sites-available目录下的 default 软连接
重新创建 
default 文件

root@ubuntu:/etc/nginx/sites-enabled# vim default

 

###
#这是默认站点设置文件,可以在这里添加通用规则
###
server {

listen 80 default_server;

####
#禁用 IP 直接访问,返回 444
####
server_name _;

return 444;

}

root@ubuntu:/etc/nginx/sites-enabled# vim domain.com


###
# domain.com 请换成自己的域名, IP 和 端口 是指真实网站的 IP 和端口,请自行更改
###
upstream domain.com {

        server 10.xxx.xxx.xxx:80;

}

server {

        listen 80;

        server_name www.domain.com domain.com;

        log_not_found off;

        charset utf-8;

        location / {

                proxy_pass http://domain.com;

                proxy_set_header    Host             $host;

                proxy_set_header    X-Real-IP        $remote_addr;

                proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;

                proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;

                proxy_redirect      off;
                
proxy_read_timeout  150; 

        }

} 

以本人网站为例:

root@ubuntu:/etc/nginx/sites-enabled# vim xiaobai.win 

upstream wuxiaobai.win {

        server 10.10.10.10:5780;

}

server {

        listen 80;

        server_name www.wuxiaobai.win wuxiaobai.win;

        log_not_found off;

        charset utf-8;

        location / {

                proxy_pass http://wuxiaobai.win;

                proxy_set_header    Host             $host;

                proxy_set_header    X-Real-IP        $remote_addr;

                proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;

                proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;

                proxy_redirect      off;

                proxy_read_timeout  150;

        }

}



 

❤ 喜欢 6259

3条回应:“nginx反向代理服务器搭建”

  1. This is very interesting, You’re a very skilled blogger.
    I have joined your feed and look forward to seeking more of your great post.
    Also, I’ve shared your web site in my social
    networks!

  2. I always emailed this website post page to all my associates,
    because if like to read it then my friends will too.

  3. Howdy! This post couldn’t be written any better! Reading this
    post reminds me of my previous room mate! He
    always kept talking about this. I will forward this post to him.
    Pretty sure he will have a good read. Thanks for sharing!

发表评论

必填项已用*标注

归档于 Ubuntu