Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

[HowTo] Configure Nginx for Wordpress Websites (VestaCP)

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
2 posts • Page 1 of 1
xorro
Posts: 87
Joined: Sun Nov 13, 2016 3:11 pm
Contact:
Contact xorro
Website Skype

Os: CentOS 6x
Web: apache + nginx
[HowTo] Configure Nginx for Wordpress Websites (VestaCP)
  • Quote

Post by xorro » Thu Sep 06, 2018 3:00 pm

You have a WordPress website and would like to switch to a Nginx web server using VestaCP? Good!

As you may know, you cannot use a .htaccess file in Nginx. The .htaccess file only works with Apache.

So let's start with basic configuration for wordpress using Nginx (VestaCP) Server

Creating a basic Nginx configuration for WordPress
Here is a basic configuration to run your WordPress website with Nginx with HTTP:

Code: Select all

# WordPress website: mysite.com and www.mysite.com
server {
    listen 80;
    server_name mysite.com www.mysite.com;

    # Logs (access et errors)
    access_log /home/mysite.com/logs/nginx/access-https.log;
    error_log /home/mysite.com/logs/nginx/error-https.log;

    # Root folder
    root /home/mysite.com/www;

    # Default file
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # Add a slash at the end of request */wp-admin
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    # Deny files starting with a . (dot)
    location ~ /\. {
        deny all;
    }

    # Add Rocket-Nginx configuration (of course !!)
    include rocket-nginx/default.conf;

    # PHP handling with FPM
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.mysite.com.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
Redirection to www

Let's say you want to redirect mysite.com to www.mysite.com, you will need to edit this line from the Basic Configuration

Code: Select all

server_name mysite.com www.mysite.com;
to

Code: Select all

server_name www.mysite.com;
You will also need to add the following section:

Code: Select all

server {
        listen 80;
        server_name     mysite.com;
        return          301 http://www.mysite.com$request_uri;
}
Note: you may need to alter your subdomain configuration to make it work.

Redirection to non-www

Let's say you want to redirect www.mysite.com to mysite.com, you will need to edit this line from the Basic Configuration.

Code: Select all

server_name mysite.com www.mysite.com;
to

Code: Select all

server_name mysite.com;
You will also need to add the following section:

Code: Select all

server {
        listen 80;
        server_name     www.mysite.com;
        return          301 http://mysite.com$request_uri;
}
Adding SSL support to your WordPress website with Nginx (VestaCP Users can use VestaCP to configure SSL)

If you want your website to support SSL (HTTPS), you'll have a buy a SSL certificate and generate your private and public keys. Once you're done, you will need to create a new configuration for your website as HTTP listens on port 80 and HTTPS listens on port 443.

You can start by taking your default configuration and simply change the following lines:

Code: Select all

server {
    listen 443;

    # SSL configuration
    ssl on;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:EDH+aRSA:!$
    ssl_prefer_server_ciphers on;

    # SSL public and private keys
    ssl_certificate /srv/ssl/www.mysite.com.pem;
    ssl_certificate_key /srv/ssl/www.mysite.com.key;

    # Basic configuration from previous section goes here...
}
For more information, you can check Configuring HTTPS servers and Module ngx_http_ssl_module directly from Nginx website
Note: you may need to alter your subdomain configuration to make it work.
Top

valentine
Posts: 16
Joined: Sat Sep 01, 2018 4:10 am

Os: Ubuntu 15x
Web: nginx + php-fpm
Re: [HowTo] Configure Nginx for Wordpress Websites (VestaCP)
  • Quote

Post by valentine » Fri Sep 07, 2018 5:56 am

There is another small possibility. If the PHP5 is still used, you can enable the htscanner module and give the possibility to use .htaccess-like file to configure PHP per directory, just like apache's htaccess.
Top


Post Reply
  • Print view

2 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

cron

Login  •  Register

I forgot my password