M
M
Michael2019-02-12 14:06:44
Nginx
Michael, 2019-02-12 14:06:44

Can't get nginx to work on two ports 80 and 443?

Hey !
I can’t overcome the config - it doesn’t pass the validity check, says that the server section should not be here,
refers to the third server block that should work on http
The task is this: the site should work on both 80 and 443 ports, so far without redirects and other things.
What will be the thoughts?

server {
    listen 80;
    server_name www.sitename.ru;
    return 301 http://sitename.ru$request_uri;
}


server {
        listen 443 ssl http2;
#       server_name sitename.ru;
        ssl_certificate /etc/letsencrypt/live/sitename.ru/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/sitename.ru/privkey.pem;
        ssl_trusted_certificate /etc/letsencrypt/live/sitename.ru/chain.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
       root   /var/www/sitename.ru/web;
        autoindex off;
        index index.html index.php;
         error_log /var/www/sitename.ru/log/er.log crit;
         access_log off;
        gzip_comp_level 5;
        gzip on;
        gzip_disable "msie6";
        gzip_types text/plain text/css application/json application/x-javascript;
        server_tokens off;
        fastcgi_buffers 8 32k;
        fastcgi_buffer_size 64k;
        client_max_body_size 100m;
        if (!-e $request_filename){
}
server {
        listen *:80;
  server_name sitename.ru;
        root   /var/www/sitename.ru/web;
  autoindex off;
        index index.html index.php;
        error_log /var/www/sitename.ru/log/error.log crit;
        access_log /var/www/sitename.ru/log/access.log combined;
  server_tokens off;
  gzip_comp_level 5;
  gzip on;
        gzip_disable "msie6";
        gzip_types text/plain text/css application/json application/x-javascript;
  fastcgi_buffers 8 32k;
  fastcgi_buffer_size 64k;
  client_max_body_size 100m;
  if (!-e $request_filename){
    	rewrite ^(.+)$ /index.php?page=$1;
}

        location /admin {
        try_files $uri $uri/ =404;
        auth_basic "Restricted Content";
        auth_basic_user_file /var/www/sitename.ru/.htpasswd;
  }



        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }


if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}


        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|svg)$ {
            expires max;
            log_not_found off;
      etag on;
        }

        location ~ \.(php|html)$ {
            try_files /1.html @php;
        }

        location @php {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/run/php/php5.6-fpm1.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
}

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Chernykh, 2019-02-12
@happy-cat

so draw 1 server if you don't need
server {
listen 80;
listen 443 ssl http2;
......

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question