【问题标题】:nginx server configuration : rewrite to local foldernginx 服务器配置:重写到本地文件夹
【发布时间】:2016-10-21 15:26:55
【问题描述】:

我目前正在配置一个带有子域的 nginx 服务器。

我将 noip.com 用于 DNS 服务,它为我提供了一个类似于 我的域名.ddns.net

由于我有子域,我想通过地址http://mydomain.ddns.net/subdomain访问它们

在服务器中,子域文件位于此处: /var/www/mydomain.ddns.net/www/subdomain

我的问题是:在 mydomain.ddns.net nginx 配置文件中编写什么代码来将http://mydomain.ddns.net/subdomain 重定向到 /var/www/mydomain.ddns.net/www/subdomain/welcome.php ?

提前感谢您的帮助

昆汀 C

【问题讨论】:

  • 子域是什么意思?看起来你在谈论子目录。子域是:foo.mydomain.ddns.net,其中 root 域是 ddns.net
  • 我想托管几个仅使用 DynDns 地址的网站。每个网站都位于文件夹 /var/www/mydomain.ddns.net/www/ 中。
  • 好的,但是如果网站的 URL 是 http://mydomain.ddns.net/foobar,那么它们只是同一网站的子资源。
  • 是的..也许..有问题吗?抱歉,我是服务器的初学者。你是说让多个网站托管在同一个 URL 上的唯一方法是使用子域,即 foo.mydomain.ddns.net 地址?我不能这样做,因为我使用的是 noip.com dyndns 服务.. 不是吗?
  • 是的,您可以在不同的文件夹中拥有不同的应用程序。这只是一个奇怪的选择,我想确保我理解你的要求。

标签: nginx


【解决方案1】:

我不是使用 nginx 服务 PHP 的专家,我现在不能尝试这个,但至少下面的配置应该让你开始。

尝试关注this guide 来调整它,而this 应该会让搜索配置文档的痛苦少一些。

user nginx nginx;

worker_processes 3;
worker_rlimit_nofile 2048;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
  worker_connections 1024;
  accept_mutex on;
  use epoll; # for Linux
}

http {
  server_tokens off;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log combined;

  sendfile on;

  server {
    listen 80;
    server_name mydomain.ddns.net;

    # To enable https
    #
    # listen 443 ssl;
    # ssl_certificate     /etc/nginx/sslfiles/certificate_chain.crt;
    # ssl_certificate_key /etc/nginx/sslfiles/certificate_key_no_passphrase.key;
    # ssl_session_cache shared:a_cache_name:1m;
    # ssl_session_timeout 5m;

    root /var/www/mydomain.ddns.net/www;

    location / {
      return 403; # forbidden
    }


    location @php_app {
      fastcgi_split_path_info ^(.+?(\.php)?)(\/.*)?$;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi_params;
    }

    location /subdomain_one/ {
      try_files $uri/index.html @php_app;
    }
  }
}

【讨论】:

  • 重启 nginx 时出现错误:pattern "^(.+?(\.php)?)(\/.*)?$" must have 2 captures in /etc/nginx/启用站点/mydomain.ddns.net
猜你喜欢
  • 2012-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-13
相关资源
最近更新 更多