Difference between revisions of "Nginx config example"

From KOP KB
Jump to: navigation, search
(Created page with "## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki....")
(No difference)

Revision as of 22:23, 10 August 2017

  1. You should look at the following URL's in order to grasp a solid understanding
  2. of Nginx configuration files in order to fully unleash the power of Nginx.
  3. http://wiki.nginx.org/Pitfalls
  4. http://wiki.nginx.org/QuickStart
  5. http://wiki.nginx.org/Configuration
  6. Generally, you will want to move this file somewhere, and start with a clean
  7. file but keep this around for reference. Or just disable in sites-enabled.
  8. Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  1. Default server configuration

server{

listen 80; server_name domainname.com www.domainname.com;

rewrite ^    https://$host$request_uri permanent;

} server {

# SSL configuration # listen 443 ssl;

       ssl_certificate /path/to/ssl/certfile.crt;
       ssl_certificate_key /path/to/ssl/key.key;

root /path/to/webroot;

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

server_name domainname.com www.domainname.com;

       include /path/from/nginx/folder/extraconfig.conf;

location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules;


}

  1. prevent .user.ini

location /.user.ini { deny all; }

  1. 3 example redirects

location /folder1 { rewrite ^(.*)$ /folder4 redirect; } location /folder2 { rewrite ^(.*)$ /folder4 redirect; } location /folder4 { rewrite ^(.*)$ /folder4 redirect; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ {

               #this is the path to your configuration for fast cgi and php

include /path/from/nginx/folder/fastcgi-php.conf;

# With php7-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/path/to/fpm/sock/file/php7.0-fpm.sock;

               expires -1;

}

  1. rewerite for wordpress 1

location /folder1/ {

       #try_files $uri $uri/ =404;
       try_files $uri $uri/ /folder1/index.php$is_args$args;
   }
  1. rewrite for wordpress 2

location /folder2/ {

       #try_files $uri $uri/ =404;
       try_files $uri $uri/ /folder2/index.php$is_args$args;
   }

location /folder3/ {

       #try_files $uri $uri/ =404;
       try_files $uri $uri/ /folder3/index.php$is_args$args;
   }

}

access_log /var/www/nginx/log/localhost-access.log;

 error_log  /var/www/nginx/log/localhost-error.log;

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