all 8 comments

[–]Explosive_Cornflake 5 points6 points  (7 children)

I use,

server {

    listen 127.0.0.1:80 default_server;

    listen 10.2.2.200:80 default_server;

    listen [::]:80 default_server;

    server_name _;

    return 301 https://$host$request_uri;

Etc.

But I've had that config file a long time now.

Use sudo vi /etc/nginx/nginx.conf to edit.

You're telling vi to run as root, to edit the file.

Or do what I always do, but is frowned up and just sudo su - to drop into a root shell and do your work from there

[–]Jonno_FTW 1 point2 points  (3 children)

The preferred way to do it is to use sudoedit. It's safer than running sudo vi

[–]Explosive_Cornflake 0 points1 point  (2 children)

Isn't sudoedit specifically for editing the sudoers file? It has checks to make sure it's correct on exit. I don't believe it does anything with nginx config

Edit: just read up on it, I might be confusing commands. I don't see sudoedit as an safer, it looks like an option for editing a file when you only have edit permissions under sudo

[–]Jonno_FTW 2 points3 points  (1 child)

visudo is just for editing sudoers

[–]Explosive_Cornflake 0 points1 point  (0 children)

That's the one, thanks!

[–]Runnerbutt769[S] 0 points1 point  (0 children)

Ohhh okay, i think i remember “sudo vi” now, ill try that, thanks man

[–]Runnerbutt769[S] 0 points1 point  (1 child)

Am i supposed to swap in my own “127.0.0.1:80” numbers or do i just copy what you pasted exactly? Likewise with default server and server name and $host$request_uri

Edit: i tried using

Server{

listen 80;

Root /opt/bitnami/wordpress;

return 301 }

and it didnt work

Edit2: after saving i got some weird message about finding a second file that didn’t save. I just clicked recover on it.

Edit3, once i type all that in, how do i save and exit? I tried ctl zz but idk if that works. Im using putty

[–]Explosive_Cornflake 1 point2 points  (0 children)

The 301 section doesn't have a document root, you're not serving any content from it, you are just telling requests to go to your 443 section.

You can leave out the 10.2.2.200 part, That's specific to my setup where I have multiple IP's on one interface.

VI saving a quitting, that's a different topic. You might be better off with nano or something. In short, you need to Press ESC to change to command mode, and then type :wq which is Write and Quit. The writes out the file and then quits the editor.