首页 > 其他 > 详细

Nginx的使用

时间:2019-12-28 10:43:31      阅读:96      评论:0      收藏:0      [点我收藏+]

 

如前言所述,您不能使用诸如/etc/init.d/nginx或的初始化脚本service nginx restart。本节教您如何控制以及如何使用已安装的Nginx。

记得在某个时候,passenger-install-nginx-module问过您在哪里安装Nginx,并询问您“前缀”,对吗?前缀是此新Nginx的安装目录。默认情况下,安装程序选择目录/opt/nginx。在本节中,我们假设您已安装到默认的前缀目录。如果您指定了不同的前缀,只需将/ opt / nginx替换为实际目录即可。

文件位置

然后,Nginx的配置文件位于中/opt/nginx/conf。其日志文件位于中/opt/nginx/logs

启动Nginx

您可以通过运行以下命令启动Nginx:

 $ sudo / opt / nginx / sbin / nginx

关闭Nginx

您可以通过使用kill命令杀死Nginx的PID来关闭它。要找出Nginx的PID是什么,请使用ps命令。例如:

$  ps auxw | grep nginx
root     3254 0.0 0.0 46644 1448 ?       Ss   12:55   0:00 nginx: master process /opt/nginx/sbin/nginx
ubuntu   3257 0.0 0.3 49188 6332 ?       S   12:55   0:00 nginx: worker process
ubuntu   7906 0.0 0.0 13772 1056 pts/1   S+   13:26   0:00 grep --color=auto nginx
或者是
$ sudo netstat -ntpl
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp       0     0 127.0.0.53:53           0.0.0.0:*               LISTEN     745/systemd-resolve
tcp       0     0 0.0.0.0:22             0.0.0.0:*               LISTEN     1168/sshd          
tcp       0     0 127.0.0.1:5432         0.0.0.0:*               LISTEN     27465/postgres  

这里,我们看到Nginx主进程具有PID 25817(您可以忽略工作进程),因此我们运行:

$ sudo kill PID

重新启动Nginx

重新启动Nginx与关闭Nginx,然后重新启动相同。例如:

$ sudo /opt/nginx/sbin/nginx

检查nginx配置文件是否正确

$ / opt / nginx / sbin / nginx -t
nginx: the configuration file /opt/nginx/sbin/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/sbin/nginx/nginx.conf test is successful

上传本地Rails工程到云服务器

因为之前我的rails工程都提交到github或者bitbucket上了(如何提交至git此处不再赘述,请查阅相关文章),所以直接通过git的方式把代码下载到server上即可

$ git clone https://XXXXXX/project.git (在github或bitbucket上面就可以找到,直接复制

这样代码就下载到服务器上了,然后安装gem

$ cd project
$ bundle install

创建数据库用户

sudo -u postgres createuser -s appname

创建生产环境数据库并执行迁移

$ RAILS_ENV=production rake db:create
$ RAILS_ENV=production rake db:migrate

Nginx的使用

原文:https://www.cnblogs.com/shxx/p/12110865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!