Setup (https) SSL on localhost for meteor development

后端 未结 3 1777
暖寄归人
暖寄归人 2021-02-01 06:50

How do you create a self signed SSL certificate to use on local server on mac 10.9?

I require my localhost serving as https://localhost

I am using t

3条回答
  •  死守一世寂寞
    2021-02-01 07:05

    Other solution is to use NGINX. Following steps are tested on Mac El Capitan, assuming your local website runs on port 3000 :

    1. Add a host to your local machine :

    Edit your host file : vi /etc/hosts

    Add a line for your local dev domain : 127.0.0.1 dev.yourdomain.com

    Flush your cache dscacheutil -flushcache

    Now you should be able to reach your local website with http://dev.yourdomain.com:3000

    2. Create a self signed SSL like explained here : http://mac-blog.org.ua/self-signed-ssl-for-nginx/

    3. Install nginx and configure it to map https traffic to your local website:

    brew install nginx

    sudo nginx

    Now you should be able to reach http://localhost:8080 and get an Nginx message.

    This is the default conf so now you have to set the https conf :

    Edit your conf file :

    vi /usr/local/etc/nginx/nginx.conf

    Uncomment the HTTPS server section and change following lines :

    server_name dev.yourdomain.com;

    Put your certificates you just created :

    ssl_certificate /path-to-your-keys/nginx.pem;

    ssl_certificate_key /path-to-your-keys/nginx.key;

    Change the location section with this one:

    location / {
              proxy_pass          http://localhost:3000;
              proxy_set_header    Host             $host;
              proxy_set_header    X-Real-IP        $remote_addr;
              proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
              proxy_set_header    X-Client-Verify  SUCCESS;
              proxy_set_header    X-Client-DN      $ssl_client_s_dn;
              proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
              proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
              proxy_read_timeout 1800;
              proxy_connect_timeout 1800;
            }
    

    Restart nginx :

     sudo nginx -s stop
     sudo nginx 
    

    And now you should be able to access https://dev.yourdomain.com

提交回复
热议问题