Difference between revisions of "Nginx config example"
From KOP KB
Line 50: | Line 50: | ||
} | } | ||
#3 example redirects | #3 example redirects | ||
− | location / | + | location /f1 { |
rewrite ^(.*)$ /folder4 redirect; | rewrite ^(.*)$ /folder4 redirect; | ||
} | } | ||
− | location / | + | location /f2 { |
rewrite ^(.*)$ /folder4 redirect; | rewrite ^(.*)$ /folder4 redirect; | ||
} | } | ||
− | location / | + | location /f3 { |
rewrite ^(.*)$ /folder4 redirect; | rewrite ^(.*)$ /folder4 redirect; | ||
} | } |
Revision as of 22:27, 10 August 2017
##
# 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.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# 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;
}
# prevent .user.ini
location /.user.ini {
deny all;
}
#3 example redirects
location /f1 {
rewrite ^(.*)$ /folder4 redirect;
}
location /f2 {
rewrite ^(.*)$ /folder4 redirect;
}
location /f3 {
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;
}
#rewerite for wordpress 1
location /folder1/ {
#try_files $uri $uri/ =404;
try_files $uri $uri/ /folder1/index.php$is_args$args;
}
#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;
}
}