简体   繁体   中英

Enable port 443 on Linux Nginx

I'm trying to enable port 443 on Linux Nginx as I'm trying to install an SSL certificate. I've ran sudo lsof -i -P -n | grep LISTEN sudo lsof -i -P -n | grep LISTEN and got the following:

rpcbind   1751      rpc    8u  IPv4   15914      0t0  TCP *:111 (LISTEN)
rpcbind   1751      rpc   11u  IPv6   15917      0t0  TCP *:111 (LISTEN)
master    2172     root   13u  IPv4   17752      0t0  TCP 127.0.0.1:25 (LISTEN)
nginx     2264     root    6u  IPv4   19741      0t0  TCP *:80 (LISTEN)
nginx     2264     root    7u  IPv6   19742      0t0  TCP *:80 (LISTEN)
nginx     2265    nginx    6u  IPv4   19741      0t0  TCP *:80 (LISTEN)
nginx     2265    nginx    7u  IPv6   19742      0t0  TCP *:80 (LISTEN)
nginx     2266    nginx    6u  IPv4   19741      0t0  TCP *:80 (LISTEN)
nginx     2266    nginx    7u  IPv6   19742      0t0  TCP *:80 (LISTEN)
sshd      7640     root    3u  IPv4 1317041      0t0  TCP *:22 (LISTEN)
sshd      7640     root    4u  IPv6 1317050      0t0  TCP *:22 (LISTEN)

sudo.netstat -tulpn | grep:443 sudo.netstat -tulpn | grep:443 doesn't give any result either.

I ran sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT but this didn't work. I did not get any results after this command.

My server is running on AWS EC2 and my security group has HTTPS enabled, but I still have the same issue.

My nginx.conf looks like this. I've added settings for a TLS enabled server listening on port 443:

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        location / {
                root /home/ec2-user;
                try_files $uri $uri/ /index.html;
#               add_header 'Access-Control-Allow-Origin' '*';

        }

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

# Settings for a TLS enabled server.

   server {
       listen       443 ssl http2;
       listen       [::]:443 ssl http2;
       server_name  _;
       root         /home/ec2-user;

       ssl_certificate "/etc/pki/nginx/server.crt";
       ssl_certificate_key "/etc/pki/nginx/private/server.key";
       ssl_session_cache shared:SSL:1m;
       ssl_session_timeout  10m;
       ssl_ciphers PROFILE=SYSTEM;
       ssl_prefer_server_ciphers on;

       # Load configuration files for the default server block.
       include /etc/nginx/default.d/*.conf;

       error_page 404 /404.html;
          location = /40x.html {
       }

       error_page 500 502 503 504 /50x.html;
           location = /50x.html {
       }
   }

First check if ngnix is running with systemctl status nginx If not then there is something wrong with config file and I guess your ssl certificates are missing. If that is the case then try to generate certificates and place in same path as you mention in your nginx.conf with owner of that dir as nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM