Php CodeIgniter和Nginx配置
我开发了我的CI应用程序,并在4台以上的Apache服务器上进行了测试,效果良好。但是当我把它上传到新的服务器Nginx时,它的url有问题。我在谷歌上搜索了很多,几乎什么都做了,但没有结果。现在问题来了: 由于项目结构和规模,我需要每个url如下: 例如: 但它不起作用。有效的方法是: 这不是我想要的 nginx配置为:Php CodeIgniter和Nginx配置,php,codeigniter,url,nginx,Php,Codeigniter,Url,Nginx,我开发了我的CI应用程序,并在4台以上的Apache服务器上进行了测试,效果良好。但是当我把它上传到新的服务器Nginx时,它的url有问题。我在谷歌上搜索了很多,几乎什么都做了,但没有结果。现在问题来了: 由于项目结构和规模,我需要每个url如下: 例如: 但它不起作用。有效的方法是: 这不是我想要的 nginx配置为: server { listen 80; listen [::]:80; root /var/nginx/www/mydomain.com/www; index inde
server {
listen 80;
listen [::]:80;
root /var/nginx/www/mydomain.com/www;
index index.php index.html index.htm;
server_name mydomain.com www.mydomain.com;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
# With php5-fpm:
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(png|jpg|jpeg|gif|ico|ttf|woff)(\?ver=[0-9.]+)?$ {
expires 1w;
}
location ~* \.(css|js|html)(\?ver=[0-9.]+)?$ {
expires 1w;
}
}您的codeIgniter config.php包含以下信息:
$config['base_url'] = "http://domain.tld/";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";
这是nginx重写规则
server {
server_name domain.tld;
root /var/www/codeignitor;
index index.html index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我也有同样的问题 我在北京有一个网站 和中的codeigniter文件夹 我只是将nginx配置更改为专门用于此codeigniter文件夹的位置 我是这样加的
location / {
try_files $uri $uri/ /index.php;
}
location /partners {
try_files $uri $uri/ /partners/index.php;
}
至于你的情况。我认为该设置应如下所示:
server {
listen 80;
listen [::]:80;
root /var/nginx/www/mydomain.com/www;
index index.php index.html index.htm;
server_name mydomain.com www.mydomain.com;
location / {
try_files $uri $uri/ /index.php;
}
#ADD THIS LINE
location /myappname {
try_files $uri $uri/ /myappname/index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
# With php5-fpm:
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(png|jpg|jpeg|gif|ico|ttf|woff)(\?ver=[0-9.]+)?$ {
expires 1w;
}
location ~* \.(css|js|html)(\?ver=[0-9.]+)?$ {
expires 1w;
}
通过运行sudonginx-t,然后重新启动nginx,确保一切正常。希望它能起作用