2016-04-28 59 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 
     } 

}