0

I install wordpress in nginx server on my localhost using debian OS, install is normally. But I only can login to my dashboard using localhost/statistik/wp-admin/index.php not in localhost/statistik/wp-admin/ because its become 403 Forbidden, as same as if I access in my frontpage (localhost/statistik/) its become 403 Forbidden too.

After my search on google, I know this problem because nginx not working without extention php, but I dont know how to acsess my frontpage, I try localhost/statistik/index.php and localhost/statistik/front-page.php still not working.

I try to change the configuration nginx of my site in /etc/nginx/sites-enabled/statistik but still working. This is my configuration, please help me.

file in /etc/nginx/sites-enabled/statistik

server {
listen 80;
listen [::]:80;
server_name statistik;
root /var/www/html/statistik;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
index index.html index.htm index.php;

# 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 / {
    try_files $uri $uri.html $uri.php /index.php?q=$uri&$args $uri/ @php;
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php7.0-fpm.sock;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

location @php {
    rewrite ^/([^/]+)(/|$) /$1.php last;
}

}

file in /etc/nginx/sites-enabled/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

file in /etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

For information I using Debian 9, NGINX 1.13.3-1, MySQL community client&server 5.7.22-1, php7.0

  • Your server name is localhost, which does not match the sites-enabled/statistik configuration block. nginx is using the server block in nginx.conf. – Richard Smith Apr 28 '18 at 12:40
  • I try change to server_name localhost or server_name localhost/statistik in file in /etc/nginx/sites-enabled/statistik, still not working, and what you mean about server block – Manyang Apr 28 '18 at 17:00
  • oh im sory, i wrong give the name of file in my question, nginx.conf are swapped with sites-enabled/default , I have correct it – Manyang Apr 28 '18 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.