Using WordPress on localhost with sub-folder in Apache is very easy. But using NGINX, it will little bit differents. Usually, we use custom domain like http://wordpress, register domain into “/etc/hosts” and define into NGINX sites-available.
But, this is not effective way. We like to access our wordpress like Apache. Access WordPress from localhost like http://localhost/wordpress will ease our development. Here are steps to do :
1. Configure /etc/nginx/sites-available/default
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | server { listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /var/www; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; # server_name_in_redirect off; location / { autoindex on; # This is cool because no php is touched for static content try_files $uri $uri/ /index.php; } location ~ .php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } |
This will list your http://localhost.
2. Adding your WordPress
Configure /etc/nginx/sites-available/default and add your wordpress :
1 2 3 | location /my-wordpress { try_files $uri $uri/ /my-wordpress/index.php; } |
Now you can access “http://localhost/my-wordpress”, also works well with URL Re-Write.