1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 商城业务-nginx-搭建域名访问环境一(反向代理配置)

商城业务-nginx-搭建域名访问环境一(反向代理配置)

时间:2022-04-22 04:46:35

相关推荐

商城业务-nginx-搭建域名访问环境一(反向代理配置)

正向代理与反向代理

正向代理:如在进行开发时访问测试环境特定网络,隐藏客户端信息

反向代理:屏蔽内网服务器信息,负载均衡访问

Nginx配置文件

nginx.conf:

# 全局块:# 配置影响 nginx 全局的指令。如:用户组, nginx进程pid存放路径,日志存放路径,配置文件引,允许生成worker process数等user nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;# events块:# 配置影响 nginx 服务器或与用户的网络连接。如:每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。events {worker_connections 1024;}# http块:# 可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入, mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。http {# http全局块# 如upstream,错误页面,连接超时等include /etc/nginx/mime.types;default_type application/octet-stream;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_nopushon;keepalive_timeout 65;#gzip on;# 会包含所有conf.d目录下的conf文件到当前cong文件中,所以我们可以在conf.d目录下新建一个conf文件来进行配置include /etc/nginx/conf.d/*.conf;}

pafcmall.conf:

复制一份 default.conf 为 pafcmall.conf:cp default.conf pafcmall.conf

# server块# 配置虚拟主机的相关参数,一个http中可以有多个server.server {listen 80;#配置pafcmall的域名地址server_name ;#charset koi8-r;#access_log /var/log/nginx/log/host.access.log main;# 配置请求的路由,以及各种页面的处理情况。location / {# 代理通过,将请求进行转交,要注意末尾要用 分号(;) 来进行结尾proxy_pass http://192.168.56.1:10000;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}

Nginx+Windows搭建域名访问环境

让 nginx 帮我们进行反向代理,所有来自原 的请求,都转到商品服务

先不使用网关,先直接配置nginx反向代理到商品服务。

先在docker中设置nginx的开机自启:

修改nginx的配置文件:

查看nginx.conf文件:

配置pafcmall.conf文件,先复制一份default.conf文件为pafcmall.conf文件:

listen 80;#配置pafcmall的域名地址server_name ;#charset koi8-r;#access_log /var/log/nginx/log/host.access.log main;location / {#代理通过,将请求进行转交proxy_pass http://192.168.56.1:10000;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。