2015-05-11 14 views
0

我有12个站点,我打算在一台具有NGinx和php5-fpm的服务器上运行。我将它们全部设置为每个conf文件使用一个服务器块,全部由主nginx.conf文件包含。它是Wordpress,PhpMyAdmin和PHP站点的组合。 wordpress和PhpMyAdmin网站工作正常,但PHP网站没有。意思是,当我拉起example.com时,Chrome说连接被拒绝,并且NGinx日志中没有传入连接的踪迹。 test.example.com会同时拉起默认站点(因为我没有配置test.example.com)。像example.com这样的基本URL在NGinx中不起作用

我复制了工作网站的nginx配置,以设置不工作的网站,但没有运气。在工作和非工作站点之间nginx配置的唯一区别是server_name指令。

经过检查并重新检查了2个多小时后,我发现server_name为pqr.example.com的网站有效,但example.com网站没有。所有的工作网站都被配置为使用子域名的URL,这可能是他们工作的原因。

我的问题是 -
1.我在配置中缺少什么使abc.com工作?
2.我有两个站点,example.com和example.net,我试图在同一台服务器上运行。这会对NGinx造成问题吗?
3. Nginx在区分example.com,test.example.com和example.net时是否存在问题?
4.我也注意到,如果www.example.net有效,www.example.com不会,反之亦然,这意味着我必须为每个网站分配名称为abc的不同子域名,例如www.example。 net和test.example.com。这是Nginx的标准/预期行为,还是我错过了某些东西?
5.我的所有基准URL自动从http://example.com重定向到http://www.example.com;我如何找出重定向发生的地方?

下面是我遇到问题的Nginx配置文件,截断以包含重要部分;请让我知道是否需要更多信息。

主要nginx.conf文件 -

user www-data www-data; 
pid /var/run/nginx.pid; 
worker_processes 4; 
worker_rlimit_nofile 100000; 

events { 
    worker_connections 4096; 
    include /etc/nginx.custom.events.d/*.conf; 
} 

http { 
    default_type application/octet-stream; 

    access_log off; 
    error_log /var/log/nginx/error.log crit; 
    ....... 
    server_tokens off; 

    include proxy.conf; 
    include fcgi.conf; 

    include conf.d/*.conf; 
    include /etc/nginx.custom.d/*.conf; 
} 

include /etc/nginx.custom.global.d/*.conf; 

这里是一个可行的博客全部工作.conf文件。所有其他网站都有这个完整的配置,因为它们只是基本的PHP网站。

server { 
    listen *:80;  

    server_name blog.example.com; 

    access_log /var/log/nginx/blog-example.access.log; 
    error_log /var/log/nginx/blog-example.error.log; 

    root /var/www/example/blog; 
    index index.html index.htm index.php; 

    # This order might seem weird - this is attempted to match last if rules below fail. 
    location/{ 
     try_files $uri $uri/ /index.php?$args; 
    } 

    # Add trailing slash to */wp-admin requests. 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 

    # Directives to send expires headers and turn off 404 error logging. 
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { 
      access_log off; log_not_found off; expires max; 
    } 

    location = /favicon.ico { 
     log_not_found off; 
     access_log off; 
    } 

    location = /robots.txt { 
     allow all; 
     log_not_found off; 
     access_log off; 
    } 

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) 
    location ~ /\. { 
     deny all; 
    } 

    # Deny access to any files with a .php extension in the uploads directory 
    # Works in sub-directory installs and also in multisite network 
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) 
    location ~* /(?:uploads|files)/.*\.php$ { 
     deny all; 
    } 

    location ~ [^/]\.php(/|$) { 

     # Zero-day exploit defense. 
     # http://forum.nginx.org/read.php?2,88845,page=3 
     # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi. 
     # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked. 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 

     fastcgi_index index.php; 
     include fcgi.conf; 
     fastcgi_pass unix:/var/run/php-fcgi-blog-example-php-fcgi-0.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

    } 

} 

这里的example.com的截断.conf文件

server { 
    listen *:80;  

    server_name example.com www.example.com test.example.com; 

    access_log /var/log/nginx/examplecom.access.log; 
    error_log /var/log/nginx/examplecom.error.log; 

    root /var/www/example/com; 
    index index.html index.htm index.php; 

    # This order might seem weird - this is attempted to match last if rules below fail. 
    location/{ 
     try_files $uri $uri/ /index.php?$args; 
    } 
    ........ 

    location ~ [^/]\.php(/|$) { 
     ...... 
     fastcgi_index index.php; 
     include fcgi.conf; 
     fastcgi_pass unix:/var/run/php-fcgi-examplecom-php-fcgi-0.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

} 

下面是example.net

server { 
    listen *:80; 

    server_name example.net www.example.net test.example.net; 

    access_log /var/log/nginx/examplenet.access.log; 
    error_log /var/log/nginx/examplenet.error.log; 

    root /var/www/example/net; 
    index index.html index.htm index.php; 

    # This order might seem weird - this is attempted to match last if rules below fail. 
    location/{ 
     try_files $uri $uri/ /index.php?$args; 
    } 
    ........ 

    location ~ [^/]\.php(/|$) { 
     ...... 
     fastcgi_index index.php; 
     include fcgi.conf; 
     fastcgi_pass unix:/var/run/php-fcgi-examplenet-php-fcgi-0.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 

回答

0

意义的截断的文件,当我拉起example.com ,Chrome表示连接被拒绝,并且在NGinx日志中没有任何传入连接的痕迹。 test.example.com会同时拉起默认站点(因为我没有配置test.example.com)。

那么,你的服务器正在监听。你有可能没有正确配置你的DNS记录,或者有DNS缓存。设置你的主机文件来测试这个理论。

+0

我在发布之前用nslookup检查了我的DNS设置,并且我的example.com的所有变体/子域都指向相同的IP。我不确定请求的去向,但问题现在已经解决。 在重启NGinx和php5-fpm的次数以及大约8小时的独立之间,这个问题已经解决了,我现在可以在没有任何配置更改的情况下访问所有子域。 它看起来像DNS缓存可能是罪魁祸首,因为这解释了为什么Chrome说拒绝,我没有看到任何关于NGinx的日志。谢谢你的回答! – radhashankark

相关问题