DEV Community

loading...
Cover image for How to configure Nginx configuration file in ubuntu for localhost port forwarding

How to configure Nginx configuration file in ubuntu for localhost port forwarding

Avinash Sharma
I am Avinash Sharma, currently studying in CMRCET. I am well versed on various Data Structures and Algorithms. Consistently do a lot of competitive programming.
・1 min read

First

cd ..
cd etc/nginx/
Enter fullscreen mode Exit fullscreen mode

This takes you to the root dir of the Nginx server
then

cd sites-available
vim YourSiteName
Enter fullscreen mode Exit fullscreen mode

Now,

server {
        listen 3000 default_server;
        listen [::]:3000 default_server;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}
Enter fullscreen mode Exit fullscreen mode

To save and exit from the vim use this command

:wq
Enter fullscreen mode Exit fullscreen mode

Now, We want to update the sites-enabled dir

cd ..
cd sites-enabled/
vim YourSiteName
Enter fullscreen mode Exit fullscreen mode
server {
        listen 3000 default_server;
        listen [::]:3000 default_server;

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}

Enter fullscreen mode Exit fullscreen mode

Now, Rur your project/application and forward the port.
In the given example the defeat port is 3000.

cd
cd yourProject 
npx http-server -p 3000
Enter fullscreen mode Exit fullscreen mode

Check out more on in-depth guide through Nginx The Nginx is a reverse proxy that enables the user to host a static and dynamic website

Discussion (1)

Collapse
avinashsharma profile image
Avinash Sharma Author

Check out more on in-depth guide through Nginx .The Nginx is a reverse proxy that enables the user to host a static and dynamic website