Skip to content

Digitalocean step by step guide to nginx configuration

Solved Configure
36 2 15.1k 1
  • @justoverclock No, probably the one inside vfgest.

    wrote on last edited by
    #8

    @phenomlab mmmhhh odd…these are not folders…but links i suppose…i dont know where should i go…

    now i’m in /etc/nginx

  • @phenomlab mmmhhh odd…these are not folders…but links i suppose…i dont know where should i go…

    now i’m in /etc/nginx

    wrote on last edited by
    #9

    @justoverclock Can you give me access to your host ? Send me the details in a PM

  • @justoverclock Can you give me access to your host ? Send me the details in a PM

    wrote on last edited by
    #10

    @phenomlab you have pm

  • wrote on last edited by
    #11

    @justoverclock Thanks. Your config appears to be in default, which is fine, but was not set correctly. In the location block, I’ve set

                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
                    proxy_set_header X-NginX-Proxy true;
    
                    proxy_pass http://127.0.0.1:8080/;
                    proxy_redirect off;
    
                    # Socket.IO Support
                    proxy_http_version 1.1;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection "upgrade";
    

    This should now work when you to to https://vfgest.it

  • @justoverclock Thanks. Your config appears to be in default, which is fine, but was not set correctly. In the location block, I’ve set

                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
                    proxy_set_header X-NginX-Proxy true;
    
                    proxy_pass http://127.0.0.1:8080/;
                    proxy_redirect off;
    
                    # Socket.IO Support
                    proxy_http_version 1.1;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection "upgrade";
    

    This should now work when you to to https://vfgest.it

    wrote on last edited by
    #12

    @phenomlab works but if i type https://www.vfgest.it/ i see a 404 error page, works only with no www

  • @phenomlab works but if i type https://www.vfgest.it/ i see a 404 error page, works only with no www

    wrote on last edited by
    #13

    @justoverclock Hold on.

  • @phenomlab works but if i type https://www.vfgest.it/ i see a 404 error page, works only with no www

    wrote on last edited by phenomlab
    #14

    @justoverclock That will work now, but your certificate binding is not correct. The certificate is for the non-www only, so you’ll get an error. Let me fix that.

  • @justoverclock That will work now, but your certificate binding is not correct. The certificate is for the non-www only, so you’ll get an error. Let me fix that.

    wrote on last edited by
    #15

    @phenomlab for sure is my fault, i’ve done all by myself with a tutorial with a certbot

  • @phenomlab works but if i type https://www.vfgest.it/ i see a 404 error page, works only with no www

    wrote on last edited by
    #16

    @justoverclock All done. Both https://vfgest.it and https://vfgest.it should work now

    You have to adjust certbot for this to work - see below command transcript executed on your host

    root@vito-fiore:/etc/nginx/sites-enabled# sudo certbot
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    
    Which names would you like to activate HTTPS for?
    We recommend selecting either all domains, or all domains in a VirtualHost/server block.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1: vfgest.it
    2: www.vfgest.it
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Select the appropriate numbers separated by commas and/or spaces, or leave input
    blank to select all options shown (Enter 'c' to cancel):
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    You have an existing certificate that contains a portion of the domains you
    requested (ref: /etc/letsencrypt/renewal/vfgest.it.conf)
    
    It contains these names: vfgest.it
    
    You requested these names for the new certificate: vfgest.it, www.vfgest.it.
    
    Do you want to expand and replace this existing certificate with the new
    certificate?
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (E)xpand/(C)ancel: E
    Renewing an existing certificate for vfgest.it and www.vfgest.it
    
    Successfully received certificate.
    Certificate is saved at: /etc/letsencrypt/live/vfgest.it/fullchain.pem
    Key is saved at:         /etc/letsencrypt/live/vfgest.it/privkey.pem
    This certificate expires on 2022-12-29.
    These files will be updated when the certificate renews.
    Certbot has set up a scheduled task to automatically renew this certificate in the background.
    
    Deploying certificate
    Successfully deployed certificate for vfgest.it to /etc/nginx/sites-enabled/vfgest
    Successfully deployed certificate for www.vfgest.it to /etc/nginx/sites-enabled/vfgest
    Your existing certificate has been successfully renewed, and the new certificate has been installed.
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you like Certbot, please consider supporting our work by:
     * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
     * Donating to EFF:                    https://eff.org/donate-le
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    root@vito-fiore:/etc/nginx/sites-enabled#
    
  • @phenomlab for sure is my fault, i’ve done all by myself with a tutorial with a certbot

    wrote on last edited by
    #17

    @justoverclock You can drop the vfgest conf file as it’s not being used

  • @justoverclock You can drop the vfgest conf file as it’s not being used

    wrote on last edited by
    #18

    @phenomlab thank you very much!!!

  • @phenomlab thank you very much!!!

    wrote on last edited by
    #19

    @justoverclock Anytime

  • @phenomlab thank you very much!!!

    wrote on last edited by phenomlab
    #20

    @justoverclock You should change your app so that it only listens on localhost or 127.0.0.1 for security reasons as you are currently exposing it publicly via port 8080. The reverse proxy means that this is not required, as nginx redirects it for you and is fully secure.

  • @justoverclock You should change your app so that it only listens on localhost or 127.0.0.1 for security reasons as you are currently exposing it publicly via port 8080. The reverse proxy means that this is not required, as nginx redirects it for you and is fully secure.

    wrote on last edited by
    #21

    @phenomlab so now this app use a server created by me with nodejs…so all the api endpoints are available through port 3030

    can i set the env variable to https://vfgest.it:3030 ?

  • @phenomlab so now this app use a server created by me with nodejs…so all the api endpoints are available through port 3030

    can i set the env variable to https://vfgest.it:3030 ?

    wrote on last edited by
    #22

    @justoverclock If the app is listening on 8080, which it typically would, then no, leave it alone. Are the endpoints intended to be public ? Typically, these aren’t accessible via nginx

  • @justoverclock If the app is listening on 8080, which it typically would, then no, leave it alone. Are the endpoints intended to be public ? Typically, these aren’t accessible via nginx

    wrote on last edited by
    #23

    @phenomlab if now i try to login, the endpoint of my api doesn’t work because of mixed content

    Mixed Content: The page at 'https://vfgest.it/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://MYSERVERIP:3030/api/login'. This request has been blocked; the content must be served over HTTPS.
    
  • @phenomlab if now i try to login, the endpoint of my api doesn’t work because of mixed content

    Mixed Content: The page at 'https://vfgest.it/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://MYSERVERIP:3030/api/login'. This request has been blocked; the content must be served over HTTPS.
    
    wrote on last edited by
    #24

    @justoverclock Yes, that’s expected. You should change your endpoint so it works over https otherwise it won’t be secure, and is then subject to eavesdropping as the traffic is being sent in clear text. From a security standpoint, this is an absolute no.

  • @justoverclock Yes, that’s expected. You should change your endpoint so it works over https otherwise it won’t be secure, and is then subject to eavesdropping as the traffic is being sent in clear text. From a security standpoint, this is an absolute no.

    wrote on last edited by
    #25

    @phenomlab ok, so i can add https, can i leave the ip or i need to add vfgest.it:3030?

  • @phenomlab ok, so i can add https, can i leave the ip or i need to add vfgest.it:3030?

    wrote on last edited by
    #26

    @justoverclock You can use either, but if the API is not meant to be exposed publicly, and should only be accessed by the app itself, then you should use 127.0.0.1. Ultimately, the design is up to you.

  • @justoverclock You can use either, but if the API is not meant to be exposed publicly, and should only be accessed by the app itself, then you should use 127.0.0.1. Ultimately, the design is up to you.

    wrote on last edited by
    #27

    @phenomlab well, i’ve learned something new, no its a private crm developed by me, so no external use 🙂


Did this solution help you?
Did you find the suggested solution useful? Support 💗 Sudonix with a coffee ☕
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics
  • Error certification on virtualmin/Nginx

    Solved Linux cert virtualmin nginx
    17
    2
    0 Votes
    17 Posts
    7k Views
    phenomlab
    @DownPW anytime
  • Is nginx necessary to use?

    Moved Solved Hosting nginx web
    2
    1 Votes
    2 Posts
    1k Views
    phenomlab
    @Panda said in Cloudflare bot fight mode and Google search: Basic question again, is nginx necessary to use? No, but you’d need something at least to handle the inbound requests, so you could use Apache, NGINX, Caddy… (there are plenty of them, but I tend to prefer NGINX) @Panda said in Cloudflare bot fight mode and Google search: Do these two sites need to be attached to different ports, and the ports put in the DNS record? No. They will both use ports 80 (HTTP) and 443 (HTTPS) by default. @Panda said in Cloudflare bot fight mode and Google search: Its not currently working, but how would the domain name know which of the two sites to resolve to without more info? Currently it only says the IP of the whole server. Yes, that’s correct. Domain routing is handled (for example) at the NGINX level, so whatever you have in DNS will be presented as the hostname, and NGINX will expect a match which once received, will then be forwarded onto the relevant destination. As an example, in your NGINX config, you could have (at a basic level used in reverse proxy mode - obviously, the IP addresses here are redacted and replaced with fakes). We assume you have created an A record in your DNS called “proxy” which resolves to 192.206.28.1, so fully qualified, will be proxy.sudonix.org in this case. The web browser requests this site, which is in turn received by NGINX and matches the below config server { server_name proxy.sudonix.org; listen 192.206.28.1; root /home/sudonix.org/domains/proxy.sudonix.org/ogproxy; index index.php index.htm index.html; access_log /var/log/virtualmin/proxy.sudonix.org_access_log; error_log /var/log/virtualmin/proxy.sudonix.org_error_log; location / { proxy_set_header Access-Control-Allow-Origin *; proxy_set_header Host $host; proxy_pass http://localhost:2000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Api-Key $http_x_api_key; } location /images { index index.php index.htm index.html; root /home/sudonix.org/domains/proxy.sudonix.org/ogproxy; } fastcgi_split_path_info "^(.+\.php)(/.+)$"; listen 192.206.28.1:443 ssl http2; ssl_certificate /home/sudonix.org/domains/proxy.sudonix.org/ssl.combined; ssl_certificate_key /home/sudonix.org/ssl.key; } The important part here is server_name proxy.sudonix.org; as this is used to “map” the request to the actual domain name, which you can see in the root section as root /home/sudonix.org/domains/proxy.sudonix.org/ogproxy; As the DNS record you specified matches this hostname, NGINX then knows what to do with the request when it receives it.
  • Optimum config for NodeBB under NGINX

    Performance nginx performance
    4
    3 Votes
    4 Posts
    2k Views
    phenomlab
    @crazycells hi - no security reason, or anything specific in this case. However, the nginx.conf I posted was from my Dev environment which uses this port as a way of not interfering with production. And yes, I use clustering on this site with three instances.
  • speed up my DigitalOcean droplet - Virtualmin

    Solved Configure digitalocean virtualmin
    10
    4 Votes
    10 Posts
    3k Views
    Hari
    @phenomlab thanks for sharing, after four or five months I will migrate to DO 2 or 4gb RAM droplet.
  • how to configure DNS records virtualmin?

    Solved Linux digitalocean dns
    26
    1
    11 Votes
    26 Posts
    10k Views
    Hari
    i think we can mark this discussion as solved learned how to install virtualmin with NGINX We can easily point the DNS by mentioning server IP at CF a name record learned how to install SSL
  • nginx can't start again

    Moved Solved Configure nginx server error
    20
    2 Votes
    20 Posts
    6k Views
    phenomlab
    @elhana-fine Yes that will happen of course if you still choose to restart the NGINX service after making a change and the test fails. The test on it’s own will state the error and the line number allowing you to fix that first
  • Digitalocean Ubuntu configuration

    Solved Linux
    33
    12 Votes
    33 Posts
    14k Views
    justoverclock
    @phenomlab thank you! not me
  • is my DMARC configured correctly?

    Solved Configure
    3
    2
    3 Votes
    3 Posts
    2k Views
    Hari
    @phenomlab said in is my DMARC configured correctly?: you’ll get one from every domain that receives email from yours. Today I have received another mail from outlook DMARC, i was referring to your reply again and found it very helpful/informative. thanks again. I wish sudonix 100 more great years ahead!