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

First

cd ..
cd etc/nginx/

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

cd sites-available
vim YourSiteName

Now,

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

ro…


This content originally appeared on DEV Community and was authored by Avinash Sharma

First

cd ..
cd etc/nginx/

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

cd sites-available
vim YourSiteName

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;
        }
}

To save and exit from the vim use this command

:wq

Now, We want to update the sites-enabled dir

cd ..
cd sites-enabled/
vim YourSiteName
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;
        }
}

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

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


This content originally appeared on DEV Community and was authored by Avinash Sharma


Print Share Comment Cite Upload Translate Updates
APA

Avinash Sharma | Sciencx (2021-05-18T19:12:07+00:00) How to configure Nginx configuration file in ubuntu for localhost port forwarding. Retrieved from https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/

MLA
" » How to configure Nginx configuration file in ubuntu for localhost port forwarding." Avinash Sharma | Sciencx - Tuesday May 18, 2021, https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/
HARVARD
Avinash Sharma | Sciencx Tuesday May 18, 2021 » How to configure Nginx configuration file in ubuntu for localhost port forwarding., viewed ,<https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/>
VANCOUVER
Avinash Sharma | Sciencx - » How to configure Nginx configuration file in ubuntu for localhost port forwarding. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/
CHICAGO
" » How to configure Nginx configuration file in ubuntu for localhost port forwarding." Avinash Sharma | Sciencx - Accessed . https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/
IEEE
" » How to configure Nginx configuration file in ubuntu for localhost port forwarding." Avinash Sharma | Sciencx [Online]. Available: https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/. [Accessed: ]
rf:citation
» How to configure Nginx configuration file in ubuntu for localhost port forwarding | Avinash Sharma | Sciencx | https://www.scien.cx/2021/05/18/how-to-configure-nginx-configuration-file-in-ubuntu-for-localhost-port-forwarding/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.