9951 explained code solutions for 126 technologies


php-wordpressHow to configure Nginx for WordPress?


  1. Install Nginx and PHP on your server.
  2. Create a new Nginx configuration file for your WordPress site.

    server {
    listen 80;
    server_name example.com;
    root /var/www/example.com;
    index index.php;
    
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    }
  3. Enable the new configuration file and restart Nginx.
    sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
    sudo systemctl restart nginx
  4. Install WordPress on your server.
  5. Configure WordPress to use the Nginx configuration.

Helpful links

Edit this code on GitHub