Nginx 反向代理

一、linux Nginx 反向代理

server {
  listen 80;
  server_name api.xxxx.com;#自己域名
  access_log off;
  index index.html index.htm index.php;
  include /usr/local/nginx/conf/rewrite/none.conf;
  root /data/wwwroot/default/api.xxxx.com;
  
  #error_page 404 = /404.html;
  #error_page 502 = /502.html;
  
        location  ~ / {
             proxy_pass http://127.0.0.1:3000;#换成自己IP
        }

  location ~ [^/]\.php(/|$) {
   
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}

重点代码:

        location  ~ / {
             proxy_pass http://自己IP:3000;
        }

Nginx 反向代理_第1张图片

 

二、windows Nginx 反向代理 (环境phpStudy)

例子:打开网址www.fncms.com转跳到www.baidu.com

server {
        listen       80;
        server_name  www.fncms.com ;
        root   "E:/phpStudy/WWW/fncms.fn321.cn";
        location / {
            index  index.html index.htm index.php;
             proxy_pass http://www.baidu.com;
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

重点加了这句话:proxy_pass http://www.baidu.com;

Nginx 反向代理_第2张图片

 

 

你可能感兴趣的:(linux系统,phpStudy)