1、端口号配置虚拟主机
访问路径:192.168.160.131:81
注意:记得开启81端口号
server {
listen 81;
server_name localhost;
# 或者
server_name 192.168.160.131;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/php/jq;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2、域名配置虚拟主机
window下访问路径:www.ng.test
Linux下访问路径:www.ng.test
server {
listen 80;
server_name www.ng.test;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/php/jq;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Linux访问域名需要配置Linux的 /etc/hosts 文件
192.168.160.131 www.ng.test
window访问域名需要配置window的 hosts 文件
192.168.160.131 www.ng.test
3、设置目录列表
当网站根目录没有索引文件 index.html index.htm index.php,设置默认显示目录
# 在不同块中的作用范围也不同,在 http 块中,表示用于对所有站点都有效 ; 在server块中,表示对指定站点有效;在 location 块中,表示对某个目录起作用。
autoindex on; #开启目录列表
# 设置精准显示文件大小还是大概显示文件大小
autoindex_exact_size off;默认为on
# 设置文件最后 一 次修改时间的格式 。默认为off
autoindex_localtime on;
4、项目部署注意问题
- pathinfo 问题,就是thinkphp URL格式需要进行匹配配置
- runtime赋予777权限的同时,需要开放selinux的拦截 chcon -R -t httpd_sys_content_rw_t 你的runtime目录路径
- 项目连接数据库需要开放selinux的拦截,目前只先关闭selinux,最好要设置selinux
- var/lib/php/创建 session 文件,并赋予 777 权限,以供保存session数据
# 查看selinux状态
sestatus
# 临时关闭 selinux
setenforce 0
# 临时开启 selinux
setenforce 1