码迷,mamicode.com
首页 > 其他好文 > 详细

nginx配置反向代理转发

时间:2019-11-19 10:33:43      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:for   conf   host文件   worker   keepaliv   windows10   tutorial   read   XML   

环境:Windows10、PHPstudy2018(nginx+mysql5.6+php7.2)

这里直接贴上nginx.conf配置文件信息。其实主要就是server的修改。把对应的路径改了就行(server也可以单独包含在vhosts.conf文件中)

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 32k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6].";

    server_names_hash_bucket_size 128;
    client_max_body_size     100m;
    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;

    server {
        listen       80;                                #前端访问的端口
        server_name  192.168.1.28;                      #前端访问的虚拟域名
        root    "E:/phpstudy/PHPTutorial/WWW/front";    #打包后的前端目录(这里是vue项目目录
        location / {                                    #必需(/下面访问***
           try_files $uri $uri/ /index.html;
        }
        location ^~ /api/ {                             #匹配到/api/的话转发到8085端口
            proxy_pass  http://erp.test.com:8085;
            proxy_set_header X-Forwarded-For  $remote_addr;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        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;
        }
    }

    server {
        listen       8085;                                      #后台api端口
        server_name  erp.test.com;                              #后台虚拟域名
        root    "E:/phpstudy/PHPTutorial/WWW/tp/public";        #api目录
        location / {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
            try_files $uri $uri/ =404;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        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;
        }
    }

### host文件添加对应域名
### 127.0.0.1 localhost
### 192.168.1.28   erp.test.com
### 配置成功后自己的机器上可以使用localhost、erp.test.com、ip、127.0.0.1访问项目(8080)
### 局域网内别人的机器使用这台机器的ipv4地址访问(8080)


include vhosts.conf;

}

 

 

nginx配置反向代理转发

标签:for   conf   host文件   worker   keepaliv   windows10   tutorial   read   XML   

原文地址:https://www.cnblogs.com/jongty/p/11887578.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!