一、使用Git Bash连接CentOS服务器
Gitbash下载:https://gitforwindows.org
使用 ssh user@remote_ip 连接到远程服务器
ssh root@140.143.240.18
测试:uname -a 查看当前系统信息
退出:logout
二、安装
Nginx下载安装(Windows安装下载地址:http://nginx.org/en/download.html)
Nginx不在CentOS官方软件源下面,查看现有源:yum repolist
1、CentOS还有一个源叫做 EPEL (Extra Packages for Enterprise)
安装EPEL YUM源
yum install epel-release
2、安装Nginx
yum install nginx
查看Nginx版本:nginx -v 或者 nginx -V
三、配置Web服务器
user nginx 改为 user root
http > server > location
1、编辑nginx.conf文件方法
找到Nginx目录:cd /etc/nginx ,查看里面文件:ls 或者 Nginx自动检查文件地址:nginx -t,找到nginx.conf物理地址后
直接打开:(如果没有vim 安装方法:yum install vim)
vim /etc/nginx/nginx.conf
2、显示行号
按住 shift+: 看到:后 输入set nu 回车,会显示行号
3、编辑
按下 i 字母 就会进入 --INSERT-- 模式
开始进行编辑
user nginx 改为 user root
http > server > location
在location 的花括号里写入 默认信息
location / { root /root/workspace/; index index.html index.htm; }
编辑完成后
按下 esc -> shift+: -> wq -> 回车(保存退出)
无任何修改
按下 esc -> shift+: -> q -> 回车(退出)
四、配置域名过程
先检查/etc/nginx/nginx.conf 文件里, include /etc/nginx/conf.d/*.conf;(默认引用了)
conf.d文件夹默认空,需要我们手动创建文件(自定义自己的域名文件名)
vim /etc/nginx/conf.d/www_oldtom_cc.conf #创建并编辑
使用根目录的 /root/workspace/文件夹存放网站代码,确保有访问权限,否则会有(Nginx访问PHP文件的File not found错误)
server { listen 80; server_name www.oldtom.cc; root /root/workspace/; index index.php index.html; access_log /var/log/nginx/access_pro_ject_club.log; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { root /root/workspace/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; try_files $uri =404; } }
五、上传网站到服务器
使用scp命令
scp -r local_dir user@ip:reomte_dir
默认支持scp命令,如果不支持可安装:yum install openssh-client
1、找到你的项目文件目录 D:\local_dir 右键选择 Git Bash Here
上传代码:scp -r ./* root@140.143.240.18:/root/workspace 这里 ./* 代表当前目录所有内容
mkdir workspace #创建文件夹:# scp -r ./* root@140.143.240.18:/root/workspace
2、查看 nginx 服务
连接服务器:
ssh root@140.143.240.18
查看nginx服务:
ps -ef | grep nginx
查看nginx.conf文件:
cat /etc/nginx/nginx.conf
启动nginx服务:
nginx
停止nginx服务:
nginx -s stop
重启nginx服务:
nginx -s reload
No write since last change (add ! to override)
今天在centos6.5上修改apache配置文件时,发现改完之后用命令q和wq和!w都不能退出来!上网一查才发现原来vi命令在直接用vi+enter进入文件的时候这些命令退出不了。
解决方法:直接用ctrl+z退出就行了
开机启动
vim /usr/lib/systemd/system/nginx.service
[Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl enable nginx.service # 设置Nginx开机启动
systemctl status nginx.service # 查看状态 systemctl start nginx.service # 启动 systemctl stop nginx.service # 停止