Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx not redirecting correctly on fresh local install #2836

Closed
coatmaker618 opened this issue Mar 8, 2021 · 20 comments
Closed

Nginx not redirecting correctly on fresh local install #2836

coatmaker618 opened this issue Mar 8, 2021 · 20 comments
Labels
help-wanted stale This issue has not had activity in a while and will be closed waiting-for-info Waiting for more information from submitter
Projects
Milestone

Comments

@coatmaker618
Copy link

coatmaker618 commented Mar 8, 2021

Tried to follow the installation on this github page and I was able to get code-server installed, but I cannot get nginx to point to it successfully!

Background: I am selfhosting this service on it's own VM. After following the instructions on this github page I was able to navigate to the code-server http URL. However, the prescribed nginx code gives me a 502 (bad gateway) rather than the desired page. Before deleting the default nginx page (not listed in instructions), I DID get the "welcome to nginx" page, so it would seem nginx is installed correctly. I'm sure it's something simple, and yes, I did change the URL in "server_name".

Any advice would be appreciated, and once i get this running, I'd be happy to update the docs for a self-hosted instructions if desired.

Reporting Disclaimer: This may be fixed with a documentation change, but as it's preventing VSCode from being usable, I'm currently considering it a bug.

@jsjoeio jsjoeio added this to Triage in code-server via automation Mar 8, 2021
@jsjoeio
Copy link
Contributor

jsjoeio commented Mar 8, 2021

Hey @coamtaker618 - thanks for the extra details in the issue and sorry to hear you're having trouble!

Apologies, I have not set code-server up manually with nginx. Have you already looked through nginx-related discussions?

Here are two that seem directly related to the issue you're running into:

@balajib-b
Copy link

balajib-b commented Mar 9, 2021

I have been using the nginx with SSL successfully for almost an year. @coamtaker618 could you please try the below nginx settings and let us know.

`server {

server_name **EXAMPLE.COM**;

location / {
    proxy_pass http://localhost:**CODE_SERVER_PORT**;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection upgrade;
    proxy_set_header Accept-Encoding gzip;
}

}`

@jsjoeio requesting you to test and confirm it.

@jsjoeio jsjoeio added the needs-investigation This issue needs to be further investigated label Mar 9, 2021
@jsjoeio jsjoeio added this to the v3.9.2 milestone Mar 9, 2021
@jsjoeio
Copy link
Contributor

jsjoeio commented Mar 9, 2021

Thanks chimming in @balajib-b! 🙌 Added this to the current milestone. Hoping I can find time to try it myself and see if it works.

@coatmaker618
Copy link
Author

coatmaker618 commented Mar 10, 2021

Still no luck :( See below for my nginx page. The only thing I changed after copy/paste is my server URL

I had a line " listen 80;" but got rid of that since you didn't have it. Didn't seem to make a difference. If I navigate to 8080 directly, it seems to work fine (I get a login prompt & vscode when I login)--but navigating to port 80 I still get a 502 (Bad Gateway). And I did make sure to restart nginx after changing the file :)

server {
    server_name code.mydomain;

    location / {
      proxy_pass http://localhost:8080/;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}

@coatmaker618
Copy link
Author

@jsjoeio I did try searching for NGINX issues with code-server but I certainly could have missed something!

#2593 may be exactly my problem but there was no further communication from poster, and the recommended suggestion was "check if code-server" is actually running. Certainly good advice, but I know it is because I can get to it on port 8080.

#2607 seems like a more complex setup, but also no further communication from the OP :( The nginx setup seems to be more complicated than mine, and so most of the advice doesn't apply. That said, I'd be happy to check nginx logs if I knew how >_<

@balajib-b
Copy link

@coamtaker618 you are accessing code server using associated domain name or using IP address.

@jsjoeio there had been a discussion on another thread about the one click deployment to clouds. I am willing to help regarding cloud deployment. Let me know your interest and support from your side.

@coatmaker618
Copy link
Author

coatmaker618 commented Mar 10, 2021

@balajib-b I'm using a domain (strictly a subdomain of a domain that I own). I have a few other services I'm hosting so I don't think the problem is a bad domain, but it never hurts to check!

@coatmaker618
Copy link
Author

Email sent

@jsjoeio
Copy link
Contributor

jsjoeio commented Mar 10, 2021

Sorry to hear that didn't help much @coamtaker618 - we'll see if we can take a look.

@balajib-b regarding the one-click deployments - thanks for offering some help! @bpmct was leading the effort and actually merged a PR yesterday: #2843

Feel free to open a new Discussion and tag myself if you have more ideas or want to get more involved!

@martinussuherman
Copy link

@coatmaker618

Try change this:

proxy_pass http://localhost:8080/;

to this:

proxy_pass http://localhost:8080;

and see if that works.

Regards,

Martinus

@coatmaker618
Copy link
Author

@martinussuherman gave that a try & no change. But thanks for the suggestion!

@jsjoeio jsjoeio modified the milestones: v3.9.2, v3.9.3, On Deck Mar 16, 2021
@martinussuherman
Copy link

@coatmaker618 sorry to hear that. Btw, I've made a repo for code-server nginx configuration here: https://github.com/martinussuherman/code-server-nginx-config based on my live setup (using docker/docker-compose for both nginx and code-server). Please take a look and hope it could help you solve your problem.

@jsjoeio if you have any input or suggestion on the above repo please let me know. Thanks.

Regards,

Martinus

@jsjoeio
Copy link
Contributor

jsjoeio commented Apr 2, 2021

@martinussuherman awesome! If you can add a README.md along with steps for setting things up (assume we know nothing), then we'd be able to use that and take a closer look.

If you need inspiration, this is the template I always use.

@martinussuherman
Copy link

@jsjoeio thanks for the suggestion and template info. I'll try make the readme asap.

Regards,

Martinus

@jsjoeio jsjoeio added waiting-for-info Waiting for more information from submitter and removed needs-investigation This issue needs to be further investigated labels Apr 5, 2021
@elreydetoda
Copy link

elreydetoda commented Apr 7, 2021

can confirm @martinussuherman's config stuff worked ( for at least getting to the application, haven't tested much more than that).

I swapped out the vscode-server for 127.0.0.1 so I didn't have to point the nginx configs to the docker resolver ( i.e. like this ) + I combined some configs.

here are my configs ( with the domain stripped ), and after I ran certbot to install my certificate:

/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
        worker_connections 768;
}
http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        gzip on;
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

/etc/nginx/snippets/websocket-proxy.conf

proxy_http_version   1.1;
proxy_set_header     Upgrade $http_upgrade;
proxy_set_header     Host $host;
proxy_set_header     X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header     X-Forwarded-Proto $scheme;
proxy_set_header     Connection "Upgrade";
proxy_cache_bypass   $http_upgrade;

/etc/nginx/conf.d/vscode.conf

server {
    server_name <domain>;
    set $backend 127.0.0.1:8080;
    location / {
       try_files /nonexistent @$http_upgrade;
    }
    location @websocket {
       proxy_set_header    X-Real-IP $remote_addr;
       proxy_set_header Accept-Encoding gzip;
       proxy_pass http://$backend;
       include /etc/nginx/snippets/websocket-proxy.conf;
    }
    location @WebSocket {
       proxy_set_header    X-Real-IP $remote_addr;
       proxy_set_header Accept-Encoding gzip;
       proxy_pass http://$backend;
       include /etc/nginx/snippets/websocket-proxy.conf;
    }
    location @ {
       proxy_set_header    X-Real-IP $remote_addr;
       proxy_set_header Accept-Encoding gzip;
       proxy_pass http://$backend;
       proxy_http_version   1.1;
       proxy_set_header     Upgrade $http_upgrade;
       proxy_set_header     Host $host;
       proxy_set_header     X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header     X-Forwarded-Proto $scheme;
       proxy_set_header     Connection keep-alive;
       proxy_cache_bypass   $http_upgrade;
    }
     location ~ \.(php|cgi|bin)
     {
        return 444;
     }
    autoindex off;
    index index.html;
    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = <domain>) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    server_name <domain>;
    listen 80;
    return 404; # managed by Certbot
}

@bpmct
Copy link
Member

bpmct commented Apr 7, 2021

@martinussuherman Awesome to see that nginx config works!

I will take a look soon and see how we can feature this setup on here awesome-code-server

@martinussuherman
Copy link

@elreydetoda I'm glad that it works for you.
@bpmct thanks, looking forward to see that.
@jsjoeio sorry, still haven't been able to do that readme yet.

Regards,

Martinus

@whattheschnell
Copy link

even with @martinussuherman configuration for both nginx and code-server in separate docker containers, i have not been able to get remote access to code-server. I'm still seeing 502 errors.

@Jackzmc
Copy link

Jackzmc commented Jun 8, 2021

I was having the same issue, and I was using oracle linux and this seems to be issue with other flavors like centos.

Running the solution stated in https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx -> setsebool -P httpd_can_network_connect 1 fixed my problem.

I was getting access denied in /var/log/nginx/error.log

@stale
Copy link

stale bot commented Dec 5, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no activity occurs in the next 5 days.

@stale stale bot added the stale This issue has not had activity in a while and will be closed label Dec 5, 2021
@stale stale bot closed this as completed Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted stale This issue has not had activity in a while and will be closed waiting-for-info Waiting for more information from submitter
Projects
No open projects
Development

No branches or pull requests

8 participants