V
V
vkrutik2019-02-27 16:27:00
Nginx
vkrutik, 2019-02-27 16:27:00

Setting up nginx http to https redirect?

server {
  server_name 123.com www.123.com;
  add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
  charset off;
  index index.php index.html;
  disable_symlinks if_not_owner from=$root_path;
  include /etc/nginx/vhosts-includes/*.conf;
  include /etc/nginx/vhosts-resources/123.com/*.conf;
  access_log /var/www/httpd-logs/123.com.access.log;
  error_log /var/www/httpd-logs/123.com.error.log notice;
  return 301 https://$host:443$request_uri;
  set $root_path /var/www/www-root/data/www/123.com/public;
  root $root_path;
  listen 123.123.123.123:80 default_server;
  error_page 404 /index.php;
  location / {
    try_files $uri $uri/ /index.php?$query_string;
    }
  
  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $root_path$fastcgi_script_name;
    fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
    include fastcgi_params;
  }
}

At the moment I have such a config to redirect http requests to https.
Please tell me how to change it so that when requests for two pages (to the main page and to 123.com/bonus) are not redirected to https

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-02-27
@dodo512

server {
    listen 123.123.123.123:80 default_server;
    
    server_name 123.com www.123.com;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    charset off;
    index index.php index.html;
    
    set $root_path /var/www/www-root/data/www/123.com/public;
    root $root_path;
    disable_symlinks if_not_owner from=$root_path;

    access_log /var/www/httpd-logs/123.com.access.log;
    error_log /var/www/httpd-logs/123.com.error.log notice;
    
    error_page 404 /index.php;

    location / {
        return 301 https://$host$request_uri;
    }
    
    location ~ ^/(bouns)?$ {
        fastcgi_param SCRIPT_FILENAME $root_path/index.php;
        fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
        include fastcgi_params;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question