Nginx代理Apache服务

使用Apache部署PHP服务的时候,80端口已经被占用(Nginx代理),则将Apache的端口配置为其他端口(如8888);并通过Nginx将Apache服务代理到80端口;实现Web服务的端口统一为80。通过如下方式实现上述过程。

Apache部署PHP服务

配置Apache端口号:

1
2
cd /etc/apache2
vi ports.conf
1
Listen 8888

配置Apacha虚拟主机服务:

1
2
cd sites-enabled
vi 000-default.conf
1
2
3
4
5
6
7
8
9
10
11
<VirtualHost *:8888>
ServerName blog.demo.com
DocumentRoot /var/www/blog/frontend/web
DirectoryIndex index.html index.php
</VirtualHost>
<Directory "/var/www/blog/frontend/web">
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>

Nginx代理Apache服务

1
2
cd /etc/nginx
vi server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server
{
listen 80;
server_name blog.demo.com;
access_log /var/log/nginx/access.blog.log main;
error_log /var/log/nginx/error.blog.log;
location / {
rewrite ^/(.*)$ //$1 last;
}
location ~* ^//.*$ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.0.1:8888;
}
}

遇到的问题及解决方法

form跳转错误。解决办法:重写action路径。

1
2
3
<?php $form = ActiveForm::begin(['id' => 'demo-form']); ?>
# code ...
<?php ActiveForm::end(); ?>

将上述默认form修改为:

1
2
3
4
5
6
7
use yii\helpers\Url;
<?php $form = ActiveForm::begin([
'id' => 'demo-form',
'action' => Url::toRoute(['site/demo']),
]); ?>
# code ...
<?php ActiveForm::end(); ?>
八宝粥 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!