nginx服务器配置:重写到本地文件夹

时间:2016-10-20 22:42:11

标签: nginx

我正在配置带有子域的nginx服务器。

我正在使用noip.com进行DNS服务,它为我提供了类似的网址 mydomain.ddns.net

由于我有子域名,我想通过地址http://freegeoip.net).I

访问它们

在服务器中,子域文件位于: /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?

提前感谢您的帮助

Quentin C

1 个答案:

答案 0 :(得分:0)

我不是使用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;
    }
  }
}