SwiftAdmin框架Webman配置nginx代理时,如何解决代理设置不正确的问题?

2026-04-01 06:501阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计872个文字,预计阅读时间需要4分钟。

SwiftAdmin框架Webman配置nginx代理时,如何解决代理设置不正确的问题?

最下面有nginx配置记录,最近项目用SwiftAdmin框架搭建的,因SwiftAdmin基于WebMan,所以启动是用php-cli方式的,加上nginx配置代理,直接不正确定义dnmp,基于Docker的LNMP一键安装程序在服务端

最下面有 nginx 配置记录

最近项目用的 SwiftAdmin 框架搭建的, 由于SwiftAdmin 基于 WebMan , 所以启动是用的php-cli 方式, 所以nginx配置代理一直不正确

dnmp 基于 Docker 的 LNMP 一键安装程序

在服务器上部署的时候用环境是 docker 的dnmp , 尝试了很多方法都不成功, 每样都测试过后, 最终成功了. 希望对大家有一点帮助 .

这里说下配置过程:

1 SwiftAdmin 项目 config/server.php 文件配置,

其它都不用改, 只要改端口号就行了. 如下图

2 配置 SwiftAdmin 项目 .env 文件

下面为什么要写容器名称, 因为docker 每次重启都会重新分配IP , 所以这里写容器名称最好. 不会重启后连接不上服务了,

什么是容器名称, 看下图: 我的mysql名称是 mysql5, 所以上图.env配置写的mysql5

3 docker-composer.yml 文件配置.

我这里用的是 dnmp

最主要的是要添加一个 links: mysql5 , 这个mysql5 就是上面说的mysql容器名称,

因为这里不配置一下php和mysql关联 , 那在访问页面的时候就会报错, 连接不上mysql,

由于项目是用 php-cli 启动的, 所以这里也是要通过php容器去连接mysql,

SwiftAdmin框架Webman配置nginx代理时,如何解决代理设置不正确的问题?

所以在php容器里做了和mysql容器的关联操作. 不做关联操作会报错连接拒绝

4 配置nginx转发到php

proxy_pass php80:82 这里为什么要写php80容器名: 因为项目是用php-cli 启动的,

所以转发的IP就要写php的, 而不是nginx或者其它的, 这里坑了我好几天,

一直都是这个地方没有配置对, 导致一直访问不正常

5 最后还有一个地方报错, 没有搞定,

就是在缩主机上运行 php start.php start 会报错, redis 连接失败,

而在php80容器里运行 php start.php start 就正常, 也不知道是什么问题,

最后发现用主机IP连接redis 就不会报错, 不过好像意义也不大了.

nginx 配置记录

server { listen 80; server_name text.baiduxxx.com; root /www/baiduxxx/public; rewrite ^/(.*)$ text.baiduxxx.com:443/$1 permanent; index index.php index.html index.htm; #charset koi8-r; access_log /dev/null; access_log /var/log/nginx/baiduxxx.access.log main; error_log /var/log/nginx/baiduxxx.error.log warn; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_php80:82; } } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ [^/]\.php(/|$) { fastcgi_pass php80:9000; include fastcgi-php.conf; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } server { listen 443 ssl; server_name text.baiduxxx.com; root /www/baiduxxx/public; index index.php index.html index.htm; #charset koi8-r; access_log /dev/null; access_log /var/log/nginx/baiduxxx.access.log main; error_log /var/log/nginx/baiduxxx.error.log warn; #error_page 404 /404.html; ssl_certificate /www/baiduxxx/public/localhost/baiduxxx.pem; ssl_certificate_key /www/baiduxxx/public/localhost/baiduxxx.key; # 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 127.0.0.1; #} location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_php80:82; } } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ [^/]\.php(/|$) { fastcgi_pass php80:9000; include fastcgi-php.conf; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }







本文共计872个文字,预计阅读时间需要4分钟。

SwiftAdmin框架Webman配置nginx代理时,如何解决代理设置不正确的问题?

最下面有nginx配置记录,最近项目用SwiftAdmin框架搭建的,因SwiftAdmin基于WebMan,所以启动是用php-cli方式的,加上nginx配置代理,直接不正确定义dnmp,基于Docker的LNMP一键安装程序在服务端

最下面有 nginx 配置记录

最近项目用的 SwiftAdmin 框架搭建的, 由于SwiftAdmin 基于 WebMan , 所以启动是用的php-cli 方式, 所以nginx配置代理一直不正确

dnmp 基于 Docker 的 LNMP 一键安装程序

在服务器上部署的时候用环境是 docker 的dnmp , 尝试了很多方法都不成功, 每样都测试过后, 最终成功了. 希望对大家有一点帮助 .

这里说下配置过程:

1 SwiftAdmin 项目 config/server.php 文件配置,

其它都不用改, 只要改端口号就行了. 如下图

2 配置 SwiftAdmin 项目 .env 文件

下面为什么要写容器名称, 因为docker 每次重启都会重新分配IP , 所以这里写容器名称最好. 不会重启后连接不上服务了,

什么是容器名称, 看下图: 我的mysql名称是 mysql5, 所以上图.env配置写的mysql5

3 docker-composer.yml 文件配置.

我这里用的是 dnmp

最主要的是要添加一个 links: mysql5 , 这个mysql5 就是上面说的mysql容器名称,

因为这里不配置一下php和mysql关联 , 那在访问页面的时候就会报错, 连接不上mysql,

由于项目是用 php-cli 启动的, 所以这里也是要通过php容器去连接mysql,

SwiftAdmin框架Webman配置nginx代理时,如何解决代理设置不正确的问题?

所以在php容器里做了和mysql容器的关联操作. 不做关联操作会报错连接拒绝

4 配置nginx转发到php

proxy_pass php80:82 这里为什么要写php80容器名: 因为项目是用php-cli 启动的,

所以转发的IP就要写php的, 而不是nginx或者其它的, 这里坑了我好几天,

一直都是这个地方没有配置对, 导致一直访问不正常

5 最后还有一个地方报错, 没有搞定,

就是在缩主机上运行 php start.php start 会报错, redis 连接失败,

而在php80容器里运行 php start.php start 就正常, 也不知道是什么问题,

最后发现用主机IP连接redis 就不会报错, 不过好像意义也不大了.

nginx 配置记录

server { listen 80; server_name text.baiduxxx.com; root /www/baiduxxx/public; rewrite ^/(.*)$ text.baiduxxx.com:443/$1 permanent; index index.php index.html index.htm; #charset koi8-r; access_log /dev/null; access_log /var/log/nginx/baiduxxx.access.log main; error_log /var/log/nginx/baiduxxx.error.log warn; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_php80:82; } } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ [^/]\.php(/|$) { fastcgi_pass php80:9000; include fastcgi-php.conf; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } server { listen 443 ssl; server_name text.baiduxxx.com; root /www/baiduxxx/public; index index.php index.html index.htm; #charset koi8-r; access_log /dev/null; access_log /var/log/nginx/baiduxxx.access.log main; error_log /var/log/nginx/baiduxxx.error.log warn; #error_page 404 /404.html; ssl_certificate /www/baiduxxx/public/localhost/baiduxxx.pem; ssl_certificate_key /www/baiduxxx/public/localhost/baiduxxx.key; # 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 127.0.0.1; #} location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_php80:82; } } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ [^/]\.php(/|$) { fastcgi_pass php80:9000; include fastcgi-php.conf; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }