nginx下配置域名
php网站在nginx.conf文件中添加配置
server {
listen 80;
server_name xxx.xx.com;//设置的域名
root /www/.../;//根目录
location / {
try_files $uri /index.php?$query_string;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:3000;//3000 php监听的端口号(nginx把接收到的请求,转发到3000端口,让php去解析文件,然后把解析的结果返回给nginx)
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
静态网站有时候设置上面的配置找不到默认的html文件时,按照下面设置
server {
listen 80;
server_name xxx.xx.com;//设置的域名
root /www/.../;//根目录
location / {
try_files $uri /index.html;
index index.php index.html index.htm;
}
location ~ /\.ht {
deny all;
}
}
在linux里面上传文件命令(使用SecureCRTPortable)
sudo rz //然后选择文件
如果文件存在 ,则使用下面命令强制覆盖
sudo rz -y
做完之后要reload nginx
sudo nginx -s reload
nginx环境
环境调试确认
1、系统网络
ping www.baidu.com
2、yum可用
3、确认关闭iptables规则
4、确认停用selinux
yum -y intall gcc gcc
初始化目录
cd /opt;mkdir app download logs work backup
主机和虚拟机可以互通,但是浏览器访问不了,nginx重启报错” /var/run/nginx.pid failed”
nginx -s reload
报错:
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
解决办法:
[root@TEST nginx]# sudo nginx -c /etc/nginx/nginx.conf
[root@TEST nginx]# nginx -s reload