linux nginx配置反向代理

查找  find / -name nginx.conf

[root@test ~]# cd /etc/nginx/conf.d
[root@test conf.d]# vi   /usr/local/nginx/conf/nginx.conf
[root@test conf.d]# vi nginx.conf
[root@test conf.d]# find / -name nginx.conf
/etc/nginx/nginx.conf
[root@test conf.d]# vi /etc/nginx/nginx.conf
[root@test conf.d]#
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

"/etc/nginx/nginx.conf" 90L, 2469C

上面得到原始的  配置文件

修改文件后

server {

        listen       80;

        server_name  www.xxx.com; #代理服务器本机的域名或者IP
#charset koi8-r; #access_log logs/host.access.log main; 
location
/ {
root html;
index index.html index.htm;
proxy_pass http:
//www.xxx.com;
}

:qw 回车

[root@test ~]# nginx -s reload 
[root@test ~]# vi /etc/nginx/nginx.conf
[root@test ~]# vi /etc/nginx/nginx.conf
[root@test ~]# nginx -s reload 
[root@test ~]# 

重启 nginx

nginx -s reload 

2.添加多个一个路由,注意:这里 buy必须是域名下对应的文件夹路径

location /buy { 
   root html; 
  index index.html index.htm;
   proxy_pass http://www.xxx.com;  
}

当访问 http://n2.xxxxx.cn/buy 则是第二个

原文地址:https://www.cnblogs.com/panjinzhao/p/14296752.html