apache - Yii2 + Nginx(代理)+ Apache(后台)
问题描述
我正在学习 NGINX,我需要使用 NGINX 设置前端网络服务器和使用 Apache 设置后端网络服务器.htaccess
这是内容/etc/nginx/sites-available/my_test5.loc
server {
charset utf-8;
client_max_body_size 128M;
listen 80;
server_name my_test5.loc;
root /var/www/my_test5.loc/web;
#root /var/www/my_test5.loc;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
deny all;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~* /\. {
# deny all;
allow all;
}
}
这是内容/etc/apache2/sites-available/my_test5.loc.conf
<VirtualHost *:8080>
<Directory /var/www/my_test5.loc/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin admin@my_test5.loc
ServerName my_test5.loc
ServerAlias www.my_test5.loc
DocumentRoot /var/www/my_test5.loc/web/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在我所做的只是主页。例如,如果我尝试导航到站点/关于我不能。我做错了什么以及如何使用这两个网络服务器?
解决方案
我认为您的设置只是index.php
因为您的location / {}
指令而正确指向,请尝试编辑您以更宽容地允许您的 Apache 访问更改此块以通过它并将特定块添加到其他类型的文件,如资产。
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|ttc|otf|eot|woff|woff2)$ {
try_files $uri $uri/
}
这样,NGINX 为您的静态文件提供服务,而 Apache 为其他所有内容提供服务。
推荐阅读
- javascript - 如何在字符串中的数字中添加逗号
- python - Python代码的组织。一个大文件与多个模块、包
- vue.js - Vue.js 延迟加载路由错误处理
- android - 如果lifecycleScope是主管,为什么它的子协程失败导致应用程序崩溃?
- laravel - 如何在子域中托管 laravel 应用程序
- python - 从 Python 中的 Amazon Kinesis 输出读取字节图像
- javascript - 使用“throw”返回函数结果是使用 throw 的正确方法吗?
- odoo-12 - 在 Odoo v12 中导入数据时出现数据超出错误
- c# - 数据表到通用列表的转换
- ios - 如何以编程方式将 UILabel 居中到 UIView?