Mac:
1.nginx查看安装位置:nginx -V
2.nginx配置文件位置:usr/local/etc/nginx/nginx.conf
3.配置文件中添加:
tp5:
location /newcms/public/ {
if (!-e $request_filename){
rewrite ^/newcms/public/(.*)$ /newcms/public/index.php?s=/$1 last;
}
}
tp3.2:
location /cms/ {
if (!-e $request_filename){
rewrite ^/cms/(.*)$ /cms/index.php?s=$1 last;
}
}
虚拟机:
1.nginx配置文件位置:vim /usr/local/nginx/conf/nginx.conf
2.编辑虚拟机hosts文件【配置域名】:vim /etc/hosts
例如:域名为www.web_icon.com
127.0.0.1 www.web_icon.com web_icon.com
::1 www.web_icon.com
3.编辑宿主机hosts文件【配置域名】:vim /etc/hosts
172.16.88.129 www.web_icon.com web_icon.com
::1 web_icon.com
4.nginx配置文件添加:
##Icon Start 配置域名访问
server {
listen 80;
server_name www.web_icon.com web_icon.com;
access_log /data/wwwlogs/access_nginx.log combined;
root /mnt/hgfs/web/icon;
index index.html index.htm index.php;
#error_page 404 /404.html;
#error_page 502 /502.html;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
deny all;
}
}
##Icon End
#无需配置域名,ip加项目名称可访问
location /icon/ {
if (!-e $request_filename){
rewrite ^/icon/(.*)$ /icon/index.php?s=$1 last;
}
}
5.重启nginx:service nginx restart