gpt4 book ai didi

Nginx yii2 配置

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:47 25 4
gpt4 key购买 nike

您好!

我正在尝试为 2 个 yii 项目配置 Nginx,frontend 用于用户,admin 用于只有一个域(没有子域)的管理员。我需要以某种方式配置它,使 mydomain.com 应该引用 frontendmydomain.com/admin 来引用 admin 。问题是我一次只能配置其中一个,这意味着我不能同时使用前端或管理员。

我尝试过的

front.conf

server {
listen 80;
server_name api.maim.experiments.uz;
return 301 https://$server_name$request_uri;
}


server {
charset utf-8;
client_max_body_size 128M;

listen 443 ssl;

ssl_certificate_key privkey.pem;
ssl_certificate fullchain.pem;

ssl_protocols TLSv1.2;

set $host_path "/home/itschool/inha_dev/frontend";

server_name api.maim.experiments.uz;
root $host_path/web;

set $yii_bootstrap "index.php";

access_log /var/log/nginx/itschool-access.log;
error_log /var/log/nginx/itschool-error.log;

location / {
index index.html $yii_bootstrap;
try_files $uri $uri/ /index.php;
}

location ~ ^/(protected|framework|themes/\w+/views) {
deny all;
}

location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}

location ~ \.php$ {

set $fsn /index.php;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}

fastcgi_pass 127.0.0.1:9002;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fsn;
}

location ~ /\.(ht|svn|git) {
deny all;
}

location ~* /\. {
deny all;
access_log off;
log_not_found off;
}
}

back.conf

server {
listen 80;
server_name api.maim.experiments.uz;
return 301 https://$server_name$request_uri;
}


server {
charset utf-8;
client_max_body_size 128M;

listen 443 ssl;

ssl_certificate_key privkey.pem;
ssl_certificate fullchain.pem;

ssl_protocols TLSv1.2;

set $host_path "/home/itschool/inha_dev/backend";

server_name api.maim.experiments.uz;
root $host_path/web;

set $yii_bootstrap "index.php";

access_log /var/log/nginx/itschool-access.log;
error_log /var/log/nginx/itschool-error.log;


location ^~ /admin {
alias /home/itschool/inha_dev/backend/web;

if (!-e $request_filename) { rewrite ^ /admin/index.php last; }

location ~ \.php$ {
if (!-f $request_filename) { return 404; }

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9002;
}
}

location ~ /\.(ht|svn|git) {
deny all;
}

location ~* /\. {
deny all;
access_log off;
log_not_found off;
}
}

我找到了一些有答案的问题,但它们对我不起作用,请帮忙。

最佳答案

我最近使用类似的配置来支持单个域上的 Web 应用程序/移动应用程序和管理面板

希望对您有所帮助。下面是配置

server {
listen 80;

set $root /var/www/html/application;

#here we go
#if backend not found in url then set root url
if ($uri !~ "^(.*)/(backend)(.*)") {
set $root /var/www/html/application/frontend/web;
}

# when request is coming from mobile then display mobile site
# you don't need this one, I just written in order to explain the mobile application navigation.
if ($http_user_agent ~* "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos") {
set $root /var/www/html/application/mobile/web;
}

root $root;

index index.php index.html index.htm index.nginx-debian.html;
server_name your_domain;

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

location / {
index index.html index.php;
if (!-e $request_filename){
rewrite ^/(.*) /index.php?r=$1 last;
}
}

location ~ /\.ht {
deny all;
}
}

另请参阅 Yii2 的官方文档以在单个域(Apache、Nginx)上设置 yii2-app-advancedCLICK HERE

您还需要知道的一件事是,如果您想将 backend/web 更改为 admin,那么您还必须在 Yii2 应用程序中进行一些更改。

关于Nginx yii2 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58252297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com