安装完centos7,全新的系统begin....
1.设置网络连接
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
配置 ONBOOT=yes
systemctl restart network
yum update
然后重启后,会下载安装一些懂东西 :y 就ok
2.安装wget
yum install wget
从这开始借鉴大帅逼的....哈哈哈
3.安装依赖
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
4.编译安装
wget https://nginx.org/download/nginx-1.12.2.tar.gz //下载
tar -zxvf nginx-1.12.2.tar.gz //解压
cd nginx-1.12.2
./configure //配置
make && make install //编译安装
5.配置防火墙:
centos7的防火墙由iptables改为firewall
打开80端口 防止访问不了
firewall-cmd --zone=public --add-port=80/tcp --permanent //--permanent永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=443/tcp --permanent
systemctl restart firewalld //重启防火墙
6.开机启动
采用的方法是将nginx新建成一个服务
touch /lib/systemd/system/nginx.service
vim /lib/systemd/system/nginx.service
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
设置开机自启动nginx服务
systemctl enable nginx.service
启动nginx服务
systemctl start nginx.service
停止开机自启动nginx服务
systemctl disable nginx.service
查看当前服务状态
systemctl status nginx.service
重新启动服务
systemctl restart nginx.service
附加:
#查看服务启动状态
netstat -nplt
#启动
/usr/local/nginx/sbin/nginx
#重启
/usr/local/nginx/sbin/nginx -s reload
#停止
/usr/local/nginx/sbin/nginx -s stop
添加站点配置
1.修改Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
#打开log_format注释
log_fromat main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
or
# 为了方便管理可以在文件nginx.conf最下面添加
# 同时nginx.conf 里的默认server 需要注释
include vhost/*.conf;
# 在/usr/local/nginx/conf 下创建文件夹vhost
mkdir vhost
在.conf 里配置站点:
# HTTP
server
{
listen 80;
server_name xxxxxx.xxxxxx.com;
index index.html index.php index.htm;
root /home/data/site/路径可修改;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location ~ /sms_codes{
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
expires 30d;
}
location ~* crossdomain\.xml$
{
access_log off;
expires 365d;
}
location ~ .*\.(js|css|swf)$
{
access_log off;
expires 12h;
}
access_log /home/logs/nginx/路径可修改/access/自定义.log main;
#兼容onethink
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=/$1 last;
}
location ~ .*\.(ico|js|css|swf)$
{
access_log off;
expires 12h;
}
}
}