Question

Setting conf file in nginx from ip to subdomain

Hello,

information about my files directory;

/etc/nginx /etc/nginx/conf.d /opt/forum/nodebb -----> where i’ve installed my nodebb

I would like to redirect my droplet ip and port to my subdomain.

I’ve managed to do sub.mydomain.com:4567 but i don’t want to let users see specific port.

i’ve successfuly installed nginx but i am having a trouble to set things right in conf file.

I did follow this guide to install nodebb on centos. https://www.rosehosting.com/blog/how-to-install-nodebb-on-a-centos-7-vps/

while i am on putty terminal, when i type **vi /etc/nginx/conf.d/yourdomain.com.conf **command, it gives me a blank page ( sort of ) ( not new window or something ) and i am adding this line as instructed

server {
    listen       80;
    server_name  yourdomain.com; // i did change to sub.mydomain.com;
    location / {
        proxy_pass        http://localhost:4567/; // i didn't change anything here

        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-Forwarded-Proto $scheme;

        proxy_redirect off;
        proxy_buffering   off;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

after i added these lines, i don’t know how to save while i am on putty so i am closing putty and it asks to me that " are you sure to close this session" so, i am saying “yes” and reopen putty to making further progress.

when i check the conf file i’ve created via filezilla, it is compiled so i can’t see if it is set as it should be or not.

I mean i can’t see this lines on file.

So Am i doing something wrong on putty ? Is there command or something that file i added those lines and save it while i am on putty without closing putty and see how it went ?

If it is not related with putty, how can i fix this ?

nodebb\config.json has set to;

{
    "url": "http://sub.mydomain.net",
    "secret": "secret thingy",
    "database": "redis",
    "redis": {
        "host": "127.0.0.1",
        "port": "6379",
        "password": "password",
        "database": "0"
    },
    "type": "literal"
}

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

@kamaln7

Thanks for your reply and your time.!

I did run sudo tail -n 50 /var/log/nginx/error.log this command and i got this;

2018/03/19 18:05:49 [crit] 7468#0: *1 connect() to 127.0.0.1:4567 failed (13: Permission denied) while connecting to upstream, 
client: XX.190.XXX.115, server: forum.mydomain.net, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4567/", 
host: "forum.mydomain.net"
2018/03/19 18:05:49 [crit] 7468#0: *1 connect() to [::1]:4567 failed (13: Permission denied) while connecting to upstream, 
client: XX.190.XXX.115, server: forum.mydomain.net, request: "GET / HTTP/1.1", upstream: "http://[::1]:4567/", 
host: "forum.mydomain.net"
2018/03/19 18:05:49 [error] 7468#0: *1 no live upstreams while connecting to upstream, 
client: XX.190.XXX.115, server: forum.mydomain.net, request: "GET /favicon.ico HTTP/1.1", 
upstream: "http://localhost/favicon.ico", host: "forum.mydomain.net", referrer: "http://forum.mydomain.net/"

I have no error.log file on /opt/nodebb ( where i’ve installed )

I did some search on google and it seems nginx related but im not sure how to solve to this and which file edit to solve.

if you just run nginx -t on its own it should give you any errors and what files if the exist

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
March 14, 2018

It’s possible that the file isn’t being saved when you close PuTTy. By doing so you are terminating the SSH session and forcing vim (the text editor) to quit. Once you run sudo vi /etc/nginx/conf.d/yourdomain.com.conf, press i and then paste in the nginx config. Then, press Escape then :. Type wq and press Enter. This will save the file and exit vim.

You might prefer to use a different editor such as nano which is a bit easier to use. sudo nano /etc/nginx/conf.d/yourdomain.com.conf, paste your config file, and press ctrl-x to save. Follow the prompt the bottom.

Make sure you restart nginx after adding the config file. That should be it.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel