2016-04-28 60 views
0

我已经安装了本地开发环境与如下:的Nginx + WordPress的页面或帖子的网址返回访问被拒绝

  • Nginx的1.8.1
  • 的WordPress 4.5.1
  • PHP 5.6.20

nginx.conf我包括/etc/nginx/conf.d/*.conf从EAC成功独立的配置文件h其他。我还没有只有一个配置文件,其中包含所有我的本地主机网站从“phpmyadmin”到开发WordPress站点的配置,我的目标是作为目录正确地联系到他们。我敢肯定,我在我的劣质nginx的配置问题,或许我应该定义URL参数重写规则,但我不能找到一个解决方案:

server { 
    listen 80; 
    server_name localhost; 

    access_log /var/log/nginx/localhost-access_log main; 
    error_log /var/log/nginx/localhost-error_log info; 

    root /var/www/localhost/htdocs/; 
    index index.php index.html index.htm; 

    location ~ \.php$ { 
        # Test for non-existent scripts or throw a 404 error 
        # Without this line, nginx will blindly send any request ending in .php to php-fpm 
        try_files $uri =404; 
        include /etc/nginx/fastcgi.conf; 
        fastcgi_pass unix:run/php-fpm.socket; 
     } 
    location /phpmyadmin { 
       alias /var/www/localhost/htdocs/phpmyadmin; 
       access_log /var/log/nginx/phpmyadmin-access_log main; 
       error_log /var/log/nginx/phpmyadmin-error_log info; 
     } 

    location /samplewordpress { 
       alias /var/www/localhost/htdocs/samplewordpress; 
       access_log /var/log/nginx/samplewordpress-access_log main; 
       error_log /var/log/nginx/samplewordpress-error_log info; 
     } 

    location /szpetra { 
       alias /var/www/localhost/htdocs/szpetra; 
       access_log /var/log/nginx/szpetra-access_log main; 
       error_log /var/log/nginx/szpetra-error_log info; 
     } 

}

我可以登录到管理页面,一切工作正常,但我尝试加载一个页面或一篇文章后,它返回“拒绝访问”消息。

任何想法来解决这个问题,而我可以保持网站的目录?

+0

你有一个不正确的nginx的配置。什么是'别名'?此外,你是否想要使用漂亮的网址?您也没有在任何位置块中定义索引文档。去阅读nginx文档,更好的,但谷歌如何设置WordPress的Nginx。 – r3wt

+0

https://codex.wordpress.org/Nginx –

回答

0

谢谢你的回答@ r3wt。不过,我想上面的配置文件是不正确的,我不想保留它(但对于我来说开发似乎没问题,因为部署我宁愿为每个站点使用单独的配置文件)。

所以,用别名部分问题,我应该已经确定try_files正确,因为我要赶链接与本地主机/ szpetra开始,所以我说了它,现在注释掉的别名部分原因我清楚地了解什么是别名 WHIS之间的区别是:

这将导致文件正在搜索中/富/酒吧/酒吧为完整URI附加

位置/酒吧{

root/foo/bar;

}

这将导致文件被搜索在/富/酒吧作为仅URI部/杆所附之后。

位置/酒吧{

别名/富/巴;

}

来源:https://forum.nginx.org/read.php?2,129656,130107

现在修改后的配置文件看起来是这样的:

server { 
    listen 80; 
    server_name localhost; 

    access_log /var/log/nginx/localhost-access_log main; 
    error_log /var/log/nginx/localhost-error_log info; 

    root /var/www/localhost/htdocs/; 
    index index.php index.html index.htm; # I used index definition here so I think I shouldn't define it under a 'location' field. 

    location ~ \.php$ { 
        try_files $uri =404; 
        include /etc/nginx/fastcgi.conf; 
        fastcgi_pass unix:run/php-fpm.socket; 
     } 
    location /phpmyadmin { 
       alias /var/www/localhost/htdocs/phpmyadmin; 
       access_log /var/log/nginx/phpmyadmin-access_log main; 
       error_log /var/log/nginx/phpmyadmin-error_log info; 
     } 

    location /samplewordpress { 
       alias /var/www/localhost/htdocs/samplewordpress; 
       access_log /var/log/nginx/samplewordpress-access_log main; 
       error_log /var/log/nginx/samplewordpress-error_log info; 
     } 

    location /szpetra { 
       # alias /var/www/localhost/htdocs/szpetra; #uncommenting alias helped me solve the problem 
       access_log /var/log/nginx/szpetra-access_log main; 
       error_log /var/log/nginx/szpetra-error_log info; 
       # index index.php index.html index.htm; # this doesn't need cause I defined the indexes above in the server{} section but I'm not sure that about this 
       try_files $uri $uri/ /szpetra/index.php?$args; # Adding this line helped me solve the problem 
     } 

}