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

error: sudo service nginx reload #59

Closed
tianke0711 opened this issue Dec 26, 2017 · 8 comments
Closed

error: sudo service nginx reload #59

tianke0711 opened this issue Dec 26, 2017 · 8 comments

Comments

@tianke0711
Copy link

tianke0711 commented Dec 26, 2017

Hi @miguelgrinberg thanks for your help!
Now I am trying to deploy the microblog in the vagrant ubuntu server.

After I created nginx configuration file for Microblog file by the command:sudo nano /etc/nginx/sites-enabled/microblog,
and input the following text in this file which mentioned in your book.

server {
    # listen on port 80 (http)
    listen 80;
    server_name _;
    location / {
        # redirect any requests to the same URL but on https
        return 301 https://\$host\$request_uri;
    }
}
server {
    # listen on port 443 (https)
    listen 443 ssl;
    server_name _;
    # location of the self-signed SSL certificate
    ssl_certificate /home/ubuntu/microblog2/certs/cert.pem;
    ssl_certificate_key /home/ubuntu/microblog2/certs/key.pem;
    # write access and error logs to /var/log
    access_log /var/log/microblog_access.log;
    error_log /var/log/microblog_error.log;
    location / {
        # forward application requests to the gunicorn server
        proxy_pass http://127.0.0.1:8000;
        proxy_redirect off;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        }
    location /static {
        # handle static files directly, without forwarding to the application
        alias /home/ubuntu/microblog2/static;
        expires 30d;
        }
 }

I want to ask that
(1): the directory of microblog in ubuntu is microblog, why you set the /home/ubuntu/microblog2/ in this file.

(2) there is error, after I run the command: sudo service nginx reload

u-xenial:~/microblog$ sudo nano /etc/nginx/sites-enabled/microblog
(venv) ubuntu@ubuntu-xenial:~/microblog$ sudo service nginx reload
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
(venv) ubuntu@ubuntu-xenial:~/microblog$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) (Result: exit-code) since Tue 2017-12-26 03:46:48 UTC; 2h 7min ago
  Process: 4632 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=1/FAILURE)
 Main PID: 3774 (nginx)
    Tasks: 3
   Memory: 2.2M
      CPU: 373ms
   CGroup: /system.slice/nginx.service
           ├─3774 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           ├─3775 nginx: worker process                           
           └─3776 nginx: worker process                           

Dec 26 05:51:46 ubuntu-xenial systemd[1]: Started A high performance web server and a reverse proxy server.
Dec 26 05:52:09 ubuntu-xenial systemd[1]: Reloading A high performance web server and a reverse proxy server.
Dec 26 05:52:09 ubuntu-xenial nginx[4565]: nginx: [emerg] unknown log format "error_log" in /etc/nginx/sites-enabled/microblog:19
Dec 26 05:52:09 ubuntu-xenial systemd[1]: nginx.service: Control process exited, code=exited status=1
Dec 26 05:52:09 ubuntu-xenial systemd[1]: Reload failed for A high performance web server and a reverse proxy server.
Dec 26 05:52:56 ubuntu-xenial systemd[1]: Started A high performance web server and a reverse proxy server.
Dec 26 05:54:21 ubuntu-xenial systemd[1]: Reloading A high performance web server and a reverse proxy server.
Dec 26 05:54:21 ubuntu-xenial nginx[4632]: nginx: [emerg] unknown log format "error_log" in /etc/nginx/sites-enabled/microblog:19
Dec 26 05:54:21 ubuntu-xenial systemd[1]: nginx.service: Control process exited, code=exited status=1
Dec 26 05:54:21 ubuntu-xenial systemd[1]: Reload failed fo

@tianke0711 tianke0711 changed the title sudo service nginx reload error: why you set microblog2 directory in the microblog.conf Dec 26, 2017
@tianke0711 tianke0711 changed the title why you set microblog2 directory in the microblog.conf why you set microblog2 directory in the nginx configuration file Dec 26, 2017
@tianke0711 tianke0711 changed the title why you set microblog2 directory in the nginx configuration file error: sudo service nginx reload Dec 26, 2017
@miguelgrinberg
Copy link
Owner

The microblog2 reference is a mistake, I'll correct that.

Does it work if you comment out the error_log and access_log lines?

@tianke0711
Copy link
Author

tianke0711 commented Dec 27, 2017

thanks @miguelgrinberg for you answer. I have corrected the directory of microblog and commented out the error_log and access_log. After run the command: sudo service nginx reload, and there is no error. But accessed the application by the browser which input: http://192.168.33.10 , and there is error as following:

192.168.33.10 uses an invalid security certificate. The certificate is not trusted because it is self-signed. The certificate is not valid for the name 192.168.33.10. Error code: SEC_ERROR_UNKNOWN_ISSUER

In the Mac before this chapter, I just run: the flask run, and it can be accessed by: 127.0.0.1:5000.

@miguelgrinberg
Copy link
Owner

This is not an error. The SSL certificate that you are using is self-signed, it is not going to be validated by the browser. From that chapter:

Because you are using a self-signed certificate, you will get a warning from the web browser, which you will have to dismiss.

@tianke0711
Copy link
Author

tianke0711 commented Dec 28, 2017

hi @miguelgrinberg thanks for your answer. But I change a browser, the error is as following image.
Could you tell me how to run the app in server, after run the command: sudo service nginx reload.
I know in Mac, I just run:flask run, then go to browser to access it by 127.0.0.0.1:5000. How about in ubuntu server.

screen shot 2017-12-28 at 16 40 38

@miguelgrinberg
Copy link
Owner

I don't use Safari that much, Does it give you an option to allow the invalid certificate? Most browsers do. If you have no choice to ignore the invalid certificate, then your options are to use a different browser (such as Chrome) or to add the certificate to the browser configuration, so that it is recognized as valid.

@tianke0711
Copy link
Author

tianke0711 commented Dec 28, 2017

hi @miguelgrinberg thanks! After I changed to chrome, it works (I don't know why safari doesn't work), although, there is sign in error, I will fix it. By the way, if I want to deploy the app to AWS ubuntu. Are there some difference with vagrant?

@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Dec 28, 2017

Deploying to an EC2 should work in the same way as in your Vagrant VM. The only difference is in how you expose a public IP address to access the application to the outside, and also that you need to set up your security groups in the same way I set up the firewall.

@miguelgrinberg
Copy link
Owner

This issue will be automatically closed due to being inactive for more than six months. Please reopen if you need more assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants