社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  NGINX

nginx子目录中的独立应用程序

Džuris • 7 年前 • 1688 次点击  

我正在尝试将一个应用程序从apache服务器移动到nginx。问题是子目录中有多个应用程序,我找不到配置服务器的正确方法。

我需要什么:

  • www.example.com 从服务 /srv/app
  • www.example.com/sub1 从服务 /srv/app/sub1
  • www.example.com/sub2 从服务 /srv/app/sub2

每个应用程序都需要相同的配置,因此我在一个片段中提取了该配置:

# snippets/app.conf

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

location /system {
    return 403;
}

# [a couple of other 403s excluded]

# Pass non-file URI to index.php
location / {
    try_files $uri $uri/ /index.php?$query_string;
}

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

# Hide .htaccess
location ~ /\.ht {
    deny all;
}

在主服务器文件中:

# [non-www and http redirects]

server {
    # [listen directives]

    server_name www.example.com;

    root /srv/app;

    include snippets/app.conf;

    location /sub1 {
        root /srv/app/sub1;
        include snippets/app.conf;
    }

    # [other sub-apps included in the same way]

    # [ssl stuff]
}

但是,这给了我一个错误:

nginx:[emerg]location“/system”在外部location“/sub1”in/etc/nginx/snippets/app.conf:5

从错误中可以明显看出 /system 被解释为“绝对的” www.example.com/system 而不是嵌套的 www.example.com/sub1/system . 我是否可以指定要将嵌套位置视为相对位置?或者我只需要为每个改变前缀的子应用重复几乎相同的配置?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46010
文章 [ 1 ]  |  最新文章 7 年前